Docker Installation
==============
sudo apt update -y (This command will update the package index cache in the server)
sudo apt install docker.io -y (docker.io)
sudo systemctl start docker (docker service will be started in runtime)
sudo systemctl enable docker (this will start the service at the boot time)
sudo docker info
Add ubuntu user in docker group
sudo usermod ubuntu -G docker
exit
sudo docker info
To pull the docker image
docker pull image_name
To search for image in docker hub
docker search image_name
To list the images available in docker host
docker image ls
To deploy container with container image in interactive mode
docker run -it --name=container_name image_name
command_to_execute_when_container_will_be_deployed
docker run -it --name=mycontainer ubuntu bash
To logout from container
Ctrl +P and Ctrl + Q
To list running containers
docker ps
To list running and stopped containers
docker ps -a
To get the container size
docker ps -s
To stop a running container
docker stop container_name/container_id
To start a stopped container
docker start container_name/container_id
To get usage of all running container
docker stats
To get usage of a specific container
docker stats container_name/container_id
To login to a running container
docker exec -it container_name/container_id bash
To remove a container from host
docker stop container_name
docker rm container_name
To forcefully remove a running container from host
docker rm -f container_name
To remove image from the host
docker rmi image_name
To forcefully remove a image which is in use by a running container (Note: This will not
impact the running container)
docker rmi -f image_name
To deploy a container in deattached mode (backgroud)
docker run -d --name=container_name image_name
docker run -d --name=web_container httpd
To rename a container
docker rename old_container_name new_container_name
To map container port with host port to expose application over host network
docker run -d -p 80:80 --name=web_container httpd
Deploying Static HTML Application in container
docker run -it --name=webcontainer -p 80:80 ubuntu bash
apt update -y
apt install apache2 git -y
cd /var/www/html
git clone https://github.com/devopstraining99/demo-app
cd /etc/init.d/
./apache2 start
Apache2 https config - https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html
Nginx https config - http://nginx.org/en/docs/http/configuring_https_servers.html
Docker hub account - https://hub.docker.com/
Creating Image with Dockerfile
touch Dockerfile
nano Dockerfile
FROM ubuntu
RUN apt update -y && apt install apache2 git -y
RUN cd /var/www/html && git clone https://github.com/devopstraining99/demo-app
ENTRYPOINT apache2ctl -DFOREGROUND
EXPOSE 80
docker build -t image_name .
# Docker file
FROM ubuntu
RUN apt update -y && apt install apache2 -y
WORKDIR /var/www/html (1) The path which will be used during docker build
2) the path in which the user will be logged-in when the container is deployed
COPY data.zip /var/www/html # data.zip
ADD data.zip /var/www/html # It will extract data.zip file into /var/www/html
ENTRYPOINT apache2ctl -DFOREGROUND ()
CMD apache2ctl -DFOREGROUND (The command can be overide by the user at the time of
container deployment)