Three things you need to know
- Dockerfile – Blueprint for building a docker image
- Image – Template for running docker container
- Container – Running process
- Kubernetes & Swarm can scale containers to the infinite workload.
If you are on Mac or Windows, download the Docker Desktop. Once you install, then you should get access to the docker from the command line.
First Command you should memorize : gives you all the containers running on your system.
Install docker extension for VSCode.: gives you the language support.
RUN npm install
COPY . .
CMD ["npm", "start"]
How do we build the docker image
Go to your project and execute it. -t to tag the project with a useful name. Build a username on Docker Hub. Use that username followed by whatever you want to call this image. You can add a version number separated by a colon. Then add the path to your docker file
docker build -t sugith/demoapp:1.0 .
After it finishes, will give you a message “Successfully build [imageid]”
You can use this image as a base image to create other images or can use to run containers.
In real life to use this image, push the image to a container registry somewhere : dockerhub or your favourite cloud provider. The command you use to do that
Developer from somewhere can use docker pull to pull that image back down.
You can use the image id or the tag name
docker run b909406d737x
port forwarding to our local machine
docker run -p 5000:8080 b909406d737x
Go to localhost:5000 to see your app.
Docker container can still be running even after you close your terminal window. Go to the docker dashboard and stop the container.
When you stop the container any state or the data you created inside of it will be lost. But there can be a situation where you want to share data across between multiple containers. The preferred way to do this is with volumes.
Volume; is a dedicated folder on the host machine. A container can create files that can remounted in to future containers or multiple containers at the same time.
docker volume create shared-stuff
docker run \
> --mount source=shared-stuff,target=/stuff
The files will stick around even after all the containers are shut down.
Docker desktop can be handy in this situation
Click on the running containers, you can see all the logs and search through them. You can do this with the commandline with
It will take you the root of the file system of the container. To keep your containers healthy, always write simple maintainable microservices
- Keep 1 process per container
For multiple processes use multiple containers. Docker has a tool called docker-compose for that. It runs multiple Docker containers at the same time.
Find this file and run all the containers together. To shutdown the containers