Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Docker
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Resources== * [https://hub.docker.com/ Docker Hub] Public Repository * [https://www.youtube.com/watch?v=fqMOX6JJhGo Docker Youtube Tutorial] ==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. * 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 [https://www.docker.com/resources/what-container here]). Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging. Docker container have their own (temporary) file system. Docker Container are created when you run an image. * A Docker Container is running on the '''Docker Host'''. Multiple container can run on the same host. The '''Docker Daemon''' as part of the host manages the containers * A Docker Container can have the '''states''' 'created', 'running', 'restarting', 'exited', 'paused', 'dead'. There could be several reasons why a running container would exit. Let's look into a few of them: ** The process inside the container was completed, and so it exited. ** The process inside the container encountered an exception while running. ** A container is intentionally stopped using the docker stop command. ** No interactive terminal was set to a container running bash. * The '''Docker Client''' steers the daemon and is accessed via terminal (Powershell, Linux shell, β¦). * A '''Docker Image''' is a unmutable 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 * Images are stored in a registry, the public registry is '''Docker Hub'''. * '''Docker Volumes''' are used to store data and to share data across containers. ===Creating Images=== # create a file called 'Dockerfile'. Dockerfiles define images. # run the following command to build an image docker build Dockerfile -t <IMAGE_NAME> // docker push <IMAGE_NAME> =====Dockerfile===== Dockerfiles contain instructions. Comment lines starts with # (hash). Docker files consists of <INSTRUCTION> <ARGUMENTS>. The first instruction is always FROM <BASE_IMAGE> // which defines the parent or base image e.g. FROM Ubuntu, by default Docker Hub is used as registry Then the RUN is executed to install the application and packages which are required RUN apt-get install python Then copy source code e.g. COPY . /app // app is a directory of the container The work directory defines the directory for the commands e.g. WORKDIR /app To run something the RUN command is used e.g. RUN pip install flask Define default command CMD ... // e.g. 'CMD sleep 5' or 'CMD ["sleep","5"] or ENTRYPOINT["<COMMAND"] // e.g. 'ENTRYPOINT ["sleep"]' and call it with 'docker run <IMAGE_NAME> [<ENTRYPOINT_PARAMETER>] =====Analyzing Images===== * there is a tool called 'dive' to analyze images ===Volumes=== * Volumes are folder on the host which are mounted to a container. ===Networks=== The network in charge of the communication process between containers is by default the '''bridge''' network or the user-defined bridge networks. * host name from container <code>host.docker.internal</code> * default networks [[File:DockerNetwork1.PNG|400px]] * the docker engine has a internal DNS server [[File:DockerNetwork2.PNG|400px]] ==Commands== ===Docker=== // general options -H=<REMOTE_DOCKER_ENGINE>:<PORT> // e.g. docker -H=<IP>:<PORT> run nginx docker build [--tag <IMAGE_NAME>] . // uses the file 'Dockerfile' in the actual directory and creates an image named <IMAGE_NAME> docker container ls docker exec // e.g. docker exec -it <CONTAINER_ID> bash docker image (ls | prune | remove <IMAGE_NAME>) docker images // lists all images docker inspect <CONTAINER_NAME> docker logs <CONTAINER_NAME> // shows log of the container docker network create <NETWORK_NAME> docker network ls docker network inspect bridge // show details for the default network 'bridge' docker pull <IMAGE> // e.g. docker pull mysql/mysql-server:latest docker ps [<OPTIONS>] // lists all running containers // -a all e.g. all containers in exited state docker restart <CONTAINER_ID> // eg. docker restart d4 docker rm <CONTAINER_NAME> docker rmi <IMAGE_NAME> // deletes an image docker run [<[https://docs.docker.com/engine/reference/commandline/run/ RUN_OPTIONS]>] <IMAGE_NAME>:<TAG> [<COMMANDS>] [<ARGS>] // runs an image // RUN_OPTIONS are: // --cpus=<NUMBER> // -d detach, run in background // -e <ENV_VARIABLE_NAME>=<VALUE> // --entrypoint <OVERWRITTEN_ENTRYPOINT> // -i use stdin // --link <CONTAINER_REF>:<CONTAINER_NAME> // --memory=<AMOUNT> // --mount type=bind,source=<HOST_DIR>,target=<CONTAINER_DIR> // moderne volume mounting // --name <NAME> // --network=<NETWORK_NAME> // -p <HOST_PORT_NUMBER>:<CONTAINER_PORT_NUMBER> // -rm // to remove the container after it has executed // -t attach terminal // -v <VOLUME_NAME>:<CONTAINER_DIR>, <VOLUME_NAME> is located in /var/lib/docker/volumes/... of the host file system, this is called volume mounting // -v <HOST_DIR>:<CONTAINER_DIR>, this is called bind mounting // <TAG> can be a version number, default is 'latest' // <COMMANDS> overwrite the CMD of the docker file // // e.g. docker run --name=TestMySQL -d mysql/mysql-server:latest docker start docker stop <CONTAINER_NAME> docker system prune // removes all stopped container, unused container, dangling images, dangling build cache docker volume (create | ls | rm | prune | β¦) // /var/lib/docker/volumes/<VOLUME_NAME> ===Docker Compose=== Compose is a tool for defining and running multi-container Docker applications. '''Services''' refer to container configurations. '''Volumes''' are disc space shared between host and container or between containers. Networks define the communication rules between containers or between containers and the host. docker-compose up // uses docker-compose.yml ====docker-compose.yml==== There are different versions of the format. =====Version 1===== <CONTAINER_NAME>: [build: <DIR>] image: <IMAGE_NAME> ports: - links: - =====Version 2===== version: 2 services: <CONTAINERNAME> ... =====Version 3===== services ... volumes: ... networks: ... ======Services====== services: <SERVICE_NAME>: [image: <IMAGE_NAME>:<TAG>] [build: <PATH_TO_DOCKERFILE>] [ports: - "<PORT_TO_BE_USED_BY_HOST>:<INTERNAL_PORT>"] // expose ports to the host [networks: - <NETWORK_NAME_USED>] // see networks section [volumes: - <HOST_PATH>:<CONTAINER_PATH>[:ro]] // ro is read-only flag [depends_on: - <SERVICE_NAME>] [environment: <ENV_NAME>: <DEFINITION> // static <ENV_NAME: "${<NAME>}"] // dynamic Environment variables can be set by an '''.env''' file or by setting them before docker-compose up. ======Networks====== networks: <NETWORK_NAME>: {}
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width