Docker
Introduction
Docker is a set of platform-as-a-service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating- system kernel and are thus more lightweight than virtual machines.
- You can launch a fully capable development environment on any computer supporting Docker; you don't have to install libraries, dependencies, download packages, mess with config files etc.
- The working environment of the application remains consistent across the whole
workflow. This means the app runs exactly the same for developer, tester, and client,
be it on development, staging or production server.
Create Dockerfile
The Docker container is launched on the basis of a Docker image, a template with the
application details. The Docker image is created with instructions written in the Dockerfile.
Build docker container
Once the dockerfile is written, the containers need to be built by running
docker build -t <container_name> <filepath_to_Dockerfile>Run docker container Once the image is built, the container needs to be up and running in order for the applications to run inside them. Run the following code to run the containers:docker run -p <>:<> -d <image_name>
To see a list of the images on your local machine, run docker images To see if your containers are up, run docker ps You can run docker ps -a to see a list of all containers (running and not).
To make the container restart automatically, run
docker run -p <>:<> --restart unless-stopped <image_name>
See this link for other options:
https://docs.docker.com/config/containers/start-containers-automatically/
Stop docker container
To stop running containers once done, run the following command:
docker stop <container_name>
Delete docker container
Containers need to be stopped before they can be deleted. Once stopped, run docker ps -a
and then run docker rm <container_name>
Delete docker images
Containers need to be stopped before deleting an image. Once stopped, run docker images
and then run docker rmi <image_name>
Run docker compose
- run
docker-compose up -d --buildto build the images