This article is to provide the overview of docker.
- "docker" to be installed on linux machine
- Provision a linux (cent os) machine (in aws/azure/google cloud or setup a linux machine on Oracle Virtual box) and install docker on the top of linux machine: yum install docker -y
- Start and enable docker service: systemctl start dockersystemctl enable docker
- Then download the docker image with below command: docker pull image_name:version
- To check the images downloaded by docker, use the below command: docker images
- Check if any container is running with below command: docker ps -a
- Download the container image with below command: docker pull imagename:version
- The detail of the docker images can be found in https://hub.docker.com/ portal
- Now run the below command to run the docker: docker run -it image_name:version
- It will straight away take you inside the container
- To avoid it, run the below command to start the container in detached mode which will start the container in background: docker run -dit image_name:version
- To give a name to the newly launched container, the below command is used: docker run -dit --name name_of_container image:version
- Access/login into the container with below command: docker attach "container_id" or "container_name"
- To exit from the container, "exit" command can be used which shut down the container
- To come out of the command, press ctrl+p+q. It will not shutdown the container
- To stop the container, use the below command: docker stop container_id or container_name
- To create a personalized docker image from a configured container, use the below command: docker commit container_name new_image_name:version
- Now run a container from this personalized image with the same command which was used earlier:
- The "docker commit" command is being used to provision the containers manually.
- It might be a query about why should we create a personalized container when the docker images are already available. The answer is all packages (like net-tools, python etc.) are not pre-installed in the docker image. That need to be configured manually. But this process can be automated with Dockerfile.
- Create a directory and create a Dockerfile inside it. Please find the sample dockerfile and its format below: From base_image:versionRUN command............
- Next, run the below command to build the image: docker build -t personalized_image_name:version directory_location_of_docker_file