Docker: Difference between revisions
| Line 33: | Line 33: | ||
Then copy source code e.g. | Then copy source code e.g. | ||
COPY . <CONTAINER_DIR> | COPY . <CONTAINER_DIR> | ||
Define default command | |||
CMD | |||
===Volumes=== | ===Volumes=== | ||
Revision as of 09:19, 1 September 2021
Resources
- Docker Hub Public Repository
History
Docker container technology was launched in 2013 as an open source Docker Engine. It leveraged existing computing concepts around containers and specifically in the Linux world, primitives known as cgroups and namespaces. Docker's technology is unique because it focuses on the requirements of developers and systems operators to separate application dependencies from infrastructure. Success in the Linux world drove a partnership with Microsoft that brought Docker containers and its functionality to Windows Server (sometimes referred to as Docker Windows containers).
Concepts
- Docker runs on a Host Operating System.
- Docker client is accessed via terminal (Powershell, Linux shell, …).
Container
- A Docker Container is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings, but in difference to VMs it does not include the (guest) OS layer (difference between Docker and VMs see here).
- Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.
- A Dcker Container is running on the Docker engine (lightweight container). Multiple container can run on the same environment.
- Docker container have their own (temporary) file system.
Images
- A Docker image is a template with instructions for creating Docker containers and is build using a file called Docker file. The Docker image is stored in the Docker Hub or in a registry.
- Docker image ---> commands (pull from repository, …) ---> Docker container
Creating Images
- create a file called 'Dockerfile'
- run
docker build Dockerfile -t <IMAGE_NAME> // docker push <IMAGE_NAME>
Dockerfile
Docker files consists of <INSTRUCTION> <ARGUMENTS>. The first instruction is always
FROM <IMAGE> // e.g. FROM Ubuntu
Then the RUN instructions gets all dependencies e.g.
RUN apt-get update
Then copy source code e.g.
COPY . <CONTAINER_DIR>
Define default command
CMD
Volumes
- Volumes are folder on the host which are mounted to a container.
Commands
docker exec docker image (ls | prune | remove <IMAGE_NAME>)
docker images // lists all images
docker inspect <CONTAINER_NAME>
docker log <CONTAINER_NAME>
docker network create
docker ps // lists all running containers // -a all e.g. all containers in exited state
docker rm <CONTAINER_NAME>
docker rmi <IMAGE_NAME> // deletes an image
docker run [<RUN_OPTIONS>] <IMAGE_NAME>:<TAG> [<COMMANDS>] [<ARGS>] // runs an image // -d detach, run in background // -e <ENV_VARIABLE_NAME>=<VALUE> // -i use stdin // -p <HOST_PORT_NUMBER>:<CONTAINER_PORT_NUMBER> // -t attach terminal // -v <HOST_DIR>:<CONTAINER_DIR> // <TAG> can be a version number, default is 'latest'
docker start docker stop <CONTAINER_NAME> docker volume (create | ls | rm | prune | …) // /var/lib/docker/volumes/<VOLUME_NAME>