He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!
Docker-compose is an official tool by docker to manage and deploy multi-container applications. Docker-compose uses a YAML file where application services are defined.
If you have any confusion between docker-compose and docker stack check out this link.
Using the docker-compose file you can build docker images and run the docker containers in a single step.
Here we will show you how to do this using a sample nodejs application
Check this link to docker-compose installation guideĀ How to install docker-compose in Linux
Step 1: Create a folder for your application
Step 2: create your sample application
vi app.js
Step 3: Create dockerfile
Step 4: create docker-compose file
Above is a simple docker-compose file that has a service called the web, docker-compose will start creating the docker image once it reaches the build section of docker-compose.yml. ‘.’ means the dockerfile present in the current path. Make sure that you maintain the DOckerfile name in the same format.
By default docker-compose file picks up Dockerfile has the dockerfile name.
Step 5: Now let’s deploy
Now you can see docker-compose started building the docker image and after that, it started the docker container with the same images. Note that all build and deploy made using a single file.
Now check the browser to verify the apps is running
Step 6: To stop the service
© 2020, Techrunnr. All rights reserved.