Difference Between DockerFile and Docker Compose-DecodingDevOps
Difference Between DockerFile and Docker Compose
Dockerfile
A Dockerfile is a text configuration file with specific syntax and pattern. From the dockerfile, docker image is generated. Dockerfile depicts bit by bit guidance of everything the orders we require to produce a docker image.
How To Create A Dockerfile
Creating a Dockerfile is as easy as creating a regular file in the system. We can land up into any directory which have proper permission to run the docker command. In the same directory, we can simply create a new file and named it as a Dockerfile.
In the below code is how the exact Dockerfile looks like.
# The line below states we will base our new image on the Latest Official Ubuntu FROM ubuntu:latest # # Identify the maintainer of an image LABEL maintainer="learn@dockerfile.com" # # Update the image to the latest packages RUN apt-get update && apt-get upgrade -y # # Install NGINX to test. RUN apt-get install nginx -y # # Expose port 80 EXPOSE 80 # # Last is the actual command to start up NGINX within our Container CMD ["nginx", "-g", "daemon off;"]
From Dockerfile, docker image can be created using command “docker build -t name .“
Docker compose
Docker compose is a kind of tool we can say to run the multiple docker application as a single service. Let’s say we need to run an application which require nginx/apache as a web server and mysql/mongodb as a database. Then we can make a single docker compose file (docker-compose.yaml) which make up the two container in a single go. Using the following command we can install the docker compose package and check the version.
1) sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2) sudo chmod +x /usr/local/bin/docker-compose
3) docker-compose --version
To create docker-compose file.
- You can make a docker-compose.yaml file and list down the requirements of the application
- To make it running, you can fire a single command “docker-compose up”
- To terminate the containers, can fire the command “docker-compose down”
Below shown is the sample docker-compose file, running nginx and php application.
version: "3" services: nginx: image: 'nginx:latest' container_name: crm_laravel_nginx restart: always tty: true ports: - "80:80" volumes: - /home/ubuntu/crm-laravel/nginx/conf.d:/etc/nginx/conf.d - /home/ubuntu/crm-laravel/nginx/nginx.conf:/etc/nginx/nginx.conf - /usr/share/nginx/html/crm-laravel-staging/:/var/www/html - /var/log/nginx:/var/log/nginx - /home/ubuntu/crm-laravel/nginx/ssl/:/etc/nginx/ssl networks: - crm_app_network links: - php php: image: 'php7-custome' container_name: crm_laravel_php restart: always volumes: - /home/ubuntu/crm-laravel/php/php.ini:/etc/php/7.3/fpm/conf.d/php.ini - /home/ubuntu/crm-laravel/php/php.ini:/etc/php/7.3/cli/conf.d/php.ini - /usr/share/nginx/html/crm-laravel-staging/:/var/www/html - /home/ubuntu/crm-laravel/supervisor:/etc/supervisor/ - /home/ubuntu/crm-laravel/logs:/var/log/ networks: - crm_app_network #node: #image: 'firebase-node:latest' # container_name: waspito_laravel_node # restart: always #env_file: #- waspito.env #networks: #- waspito_app_network networks: crm_app_network: driver: bridge
Advantage of docker-compose over Dockerfile
The major difference between dockerfile and docker-compose is docker-compose can run multiple containers from a single file unlike dockerfile.Hence, make it easier to manage the task of administrators.Another benefit of docker-compose is it provides higher security by isolating multiple containers over the same network. The last and the major benefit is it enhances productivity by reducing the time it takes to perform tasks.
- diff between docker compose and dockerfile
- difference between docker compose and dockerfile
- dockerfile and docker compose differences
- difference between dockefile and docker compose