Docker run

Running docker container

  • Run the following command to start an ubuntu container
docker run ubuntu:latest echo "Welcome to Ubuntu"

welcome ubuntu docker

  • Run the following command to start an ubuntu container with interactive bash shell
docker run --name samplecontainer -it ubuntu:latest /bin/bash

docker interactive bash

Find your containers

  • Listing running containers
docker ps

docker ps

  • Listing all containers (running/stopped)
docker ps -a

docker ps -a

Listing docker images

docker images

docker images

Running container in detached Mode

  • Run an alpine container in the background
docker run --name pingcontainer -d alpine:latest ping 127.0.0.1 -c 50
  • Looking at the logs (stdout) of a container
docker logs -f pingcontainer

docker detach logs

Running nginx container and access the service

docker run -d --name nginxalpine -p 7777:80 nginx:alpine
  • Accessing the container service from the host system using mapped port
curl localhost:7777

accessing nginx from host

  • Accessing the container service using the container IP and container port
docker exec -it nginxalpine sh

ip addr

curl 172.17.0.2:80

accessing nginx from container port

results matching ""

    No results matching ""