Learn Docker-https://www.docker.com/get-started https://docker-curriculum.com/
docker container run hello-world
docker container run alpine sh docker container run -it alpine sh # Run interactively
cat /etc/os-release uname -r
Use Official Tag docker images
docker container ls -a # List all containers hostname # hostname of the container docker container start 'Container name' # start the container docker container attach 'Container name' # attach/open the running container docker container run 'image name' # Will always start new container docker container run -itd 'image name' # Will start new container in detached mode
docker container rm 'hostname' # Remove the container with hostname docker container rm $(docker container ls -aq) # Remove all containers docker image ls docker image rm 'image-name'
docker container run --rm hello-world # Run and delete the container after run docker container --name container1 hello-world # Will create container with customised name Container1
docker container run nginx docker container run -p 80:80 nginx # open browser with localhost to see the service docker container run -p 8080:80 nginx # open browser with localhost:8080
docker container run -p 80:80 --volume /media/praveen/coding/practise/docker/html:/usr/share/nginx/html nginx
docker achieves isolation through kernal namespaces.
There are three namespaces:
- Mount (mnt)
- Process ID (pid)
- Network (net)
Create two containers with alpine image in two terminals
Try the following commands
- ls -l
- ps -ef
- ipaddr
touch a file in container, which is not seen in another container ipaddr of both containers will be different
docker container run -it --rm --name c2 alpine sh docker container run -it --rm --name c1 alpine sh
ifconfig eth0
use ping ip-address of c2 in c1 to communicate with each other
docker container run -it --rm --name c3 --link c1 alpine sh
ping c1 will work in c3
docker network ls
docker network create test
docker container run -it --rm --name c1 --network test alpine sh docker container run -it --rm --name c2 --network test alpine sh
ping c1 and ping c2 will work in respective containers
export DOCKER_HIDE_LEGACY_COMMANDS=true
in ~/.bashrc or ~/.zshrc