Docker: Difference between revisions
(Created page with "== Installing == Visit [https://docs.docker.com/engine/install/ubuntu Docker's documentation installing Docker engine on Ubuntu] for instructions on how to install the very la...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
sudo apt install docker.io | sudo apt install docker.io | ||
</pre> | </pre> | ||
== Images and Containers == | |||
With Docker you create and manage ''images'' and ''containers''. Images are templates for runtime environments. Containers are created (''instantiated'') from images. Each container is an independent environment in which your software product executes. Containers can be used by servers to handle requests from multiple clients in isolated environments. Containers are also useful in software development, where the software is built and tested in discardable containers created from images of fully specified build and run environments. | |||
<br /> | |||
== Dockerfile == | |||
The environment inside of a Docker image is defined by the instructions that the Docker image builder picks up from a file. The default expected name for this file is ''Dockerfile''. | |||
If your Dockerfile has a different name, you need to provide that file name to the ''build'' command: | |||
<pre class="terminal"> | |||
docker build -t MyImage -f /path/to/MyDockerFileName | |||
</pre> | |||
<br /> | |||
The [https://docs.docker.com/engine/reference/builder/ Dockerfile Reference] describes the commands that can be issued in a Dockerfile | |||
<br /> | |||
== Docker Compose == | |||
Docker Compose takes the role of the Docker command line interface and lets you send commands to the Docker engine by elegantly specifying a build/run configuration in a YAML file instead of, e.g., creating a shell script with Docker CLI commands. For example, the following Docker commands for building an image and instantiating a container | |||
<pre class="terminal"> | |||
docker build -t my-app . | |||
docker run --rm -tip 3000:3000 -n my-app my-app | |||
</pre> | |||
can be be expressed by this '''docker-compose.yml''' file: | |||
<pre class="code"> | |||
version: "3.8" | |||
services: | |||
app: | |||
build: ./ | |||
ports: | |||
- 3000:3000 | |||
</pre> | |||
<br/> | |||
The configuration defined in the YAML file is then realized with the command | |||
<pre class="terminal"> | |||
docker-compose up --build | |||
</pre> | |||
where the ''--build'' option triggers a rebuild of the image. Note also that ''docker-compose'' automatically removes containers that have exited. | |||
<br/> |
Latest revision as of 2021-05-29T14:05:26
Installing
Visit Docker's documentation installing Docker engine on Ubuntu for instructions on how to install the very latest version, including the Docker GPG keys. You can also install Docker from Ubuntu's own package repositories via
sudo apt install docker.io
Images and Containers
With Docker you create and manage images and containers. Images are templates for runtime environments. Containers are created (instantiated) from images. Each container is an independent environment in which your software product executes. Containers can be used by servers to handle requests from multiple clients in isolated environments. Containers are also useful in software development, where the software is built and tested in discardable containers created from images of fully specified build and run environments.
Dockerfile
The environment inside of a Docker image is defined by the instructions that the Docker image builder picks up from a file. The default expected name for this file is Dockerfile. If your Dockerfile has a different name, you need to provide that file name to the build command:
docker build -t MyImage -f /path/to/MyDockerFileName
The Dockerfile Reference describes the commands that can be issued in a Dockerfile
Docker Compose
Docker Compose takes the role of the Docker command line interface and lets you send commands to the Docker engine by elegantly specifying a build/run configuration in a YAML file instead of, e.g., creating a shell script with Docker CLI commands. For example, the following Docker commands for building an image and instantiating a container
docker build -t my-app . docker run --rm -tip 3000:3000 -n my-app my-app
can be be expressed by this docker-compose.yml file:
version: "3.8" services: app: build: ./ ports: - 3000:3000
The configuration defined in the YAML file is then realized with the command
docker-compose up --build
where the --build option triggers a rebuild of the image. Note also that docker-compose automatically removes containers that have exited.