Docker file vs Docker compose

Docker file vs Docker compose

Dockerfile is used to create image of our designed application, while using compose we run multi-container applications for our created docker file image.

In our application based on features we can create multiple docker files and run all images using docker compose.

Create local app using docker image (node js, mongo db, redis) > Create your own docker image of app > Buid image >Use docker compose to run your app container

whenever we make any changes to our code directory on local machine or to docker file, we need to re build our docker file image again with diff name or delete older one to create new with same name.

All docker images has syntax of- FROM, ENV, RUN, COPY, CMD

Use cmd- 'Docker images' to view all images on your host

we create new directory on container, copy folder from host to the same folder created in container and execute run cmd using docker file as per below example.

once docker file is created we buid image out of it by "docker build -t myapp:1.0 ." - (. specifies current directory)

Delete container using cmd- docker rm {container id} or docker rmi {container id}

This way using docker file we can build docker image of our own application

Note: Good to save devlopment files in one app folder and rest files like docker file, compose file, other files in other folder, so we can copy only app directory while building our docker image.