Show installed docker version
docker version
login to your docker hub
docker login
search image
docker search <image-name>
pull the image
docker pull <image-name>
pull image from your repo
docker pull <login-id/repo-name:imagename>
docker pull mkn400/webapp_demo
Create Dockerfile
vi Dockerfile
FROM busybox
CMD echo "Hello world! This is my first Docker image."
Build image from Dockerfile
docker build .
re-tagging
docker -t <image> <newimage>
docker -t ubuntu ubuntu:20.04
re-tagging for your docker repo
docker -t <existing-image> <hub-user/repo-name:tag>
docker -t ubuntu mkn400/ubuntu:20.04
commit the changes before push
docker commit <hub-user/repo-name:tag>
docker commit mkn400/ubuntu:20.04
Create image from container
docker commit CONTAINER-NAME <docker_account_id>/container:<tage_name>
docker commit webapp mkn400/ubuntu:apache2
save image to tar file
docker save image >> file
docker save nginx >> nginx.tar
Load an image from tar file
docker load -i TARFILE
docker load -i nginx.tar
push image to your docker repo
docker push <docker-username>/<image-name:tag-name>
docker push mkn400/simple-projects:myimage
Delete an image
docker rmi <image-name>
Show a list of all images
docker images
Delete danging images
docker image prune
Delete all unused images
docker image prune -a
start a new container from image
docker run image
docker run nginx
assign name to container
docker run --name container-name image
docker run --name web nginx
map a ports to container
docker run -p HOST-PORT:CONTAINER-PORT IMAGE
docker run -p 8080:80 nginx
map all ports
docker run -P image
docker run -P nginx
assign a hostname
docker run --hostname HOSTNAME image
docker run --hostname srv nginx
add --dns entry
docker run --add-host HOSTNAME:ip image
docker run --add-host ns1:1.2.3.4 nginx
map a local directory to container
docker run -v HOSTDIR:CONTAINEDIR IMAGE
docker run -v ~/:/usr/share/nginx/html nginx
map a docker volume to the container
docker run -v <VOLUMENAME>:<CONTAINER-DIR>
docker run -v nginxhtml:/usr/share/nginx/html
#if the volume not available automaticaly volume will create
change the entrypoint
docker run -it --entrypoint EXECUTABLE IMAGE
docker run -it --entrypoint bash nginx
run contaner in detach mode
docker run -d IMAGE
docker run -d nginx
Show a list of containers
docker ps
Show list of all containers
docker ps -a
Delete a container
docker rm CONTAINER / ID
docker rm web
Delete running container
docker stop <CONTAINER-NAME / ID >
docker rm <CONTAINER-NAME / ID >
docker stop web
docker rm web
OR
docker rm -f CONTAINER / ID
docker rm -f web
Delete stoped containers
docker container prune
Stop a running container
docker stop CONTAINER
docker stop web
Start a stoped container
docker start CONTAINER
docker start web
Copy a file from container to host
docker cp CONTAINER:SOURCE TARGET
docker cp web:/index.html index.html
Copy a file from container to host
docker cp TARGET CONTAINER:SOURCE
docker cp index.html web:/index.html
Start a shell inside a running container
docker -it CONTAINER EXECUTABLE
docker -it web bash
Rename a container
docker rename OLD_NAME NEW_NAME
docker rename 096 web
or
docker rename web webapp
Create an image out of container
docker commit CONTAINER
docker commit web
Show the logs of the container
docker logs CONTAINER-NAME
docker logs web
Show the status of running containers
docker status
Show the processes of container
docker top CONTAINER-NAME
docker top web
Get detailed information of object
docker inspect CONTAINER-NAME
docker inspect web
Show all modified files in container
docker diff CONTAINER-NAME
docker diff web
Show mapped ports of container
docker port CONTAINER-NAME
docker port web
Docker Volumes Docker Networking
The projects contains two container of httpd and mysql integrated each.