Docker run
Running docker container
- Run the following command to start an ubuntu container
docker run ubuntu:latest echo "Welcome to Ubuntu"
- Run the following command to start an ubuntu container with interactive bash shell
docker run --name samplecontainer -it ubuntu:latest /bin/bash
Find your containers
- Listing running containers
docker ps
- Listing all containers (running/stopped)
docker ps -a
Listing 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
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 the container service using the container IP and container port
docker exec -it nginxalpine sh
ip addr
curl 172.17.0.2:80