mirror of https://github.com/docker/docs.git
Update part 1 (#5806)
This commit is contained in:
parent
a64a76ca11
commit
3fbcb00c7d
Binary file not shown.
After Width: | Height: | Size: 652 KiB |
|
@ -56,128 +56,172 @@ redirect_from:
|
||||||
|
|
||||||
{% include_relative nav.html selected="1" %}
|
{% include_relative nav.html selected="1" %}
|
||||||
|
|
||||||
Welcome! We are excited you want to learn how to use Docker.
|
Welcome! We are excited that you want to learn Docker. The _Docker Get Started Tutorial_
|
||||||
|
teaches you how to:
|
||||||
|
|
||||||
In this six-part tutorial, you will:
|
1. Set up your Docker environment (on this page)
|
||||||
|
2. [Build an image and run it as one container](part2.md)
|
||||||
|
3. [Scale your app to run multiple containers](part3.md)
|
||||||
|
4. [Distribute your app across a cluster](part4.md)
|
||||||
|
5. [Stack services by adding a backend database](part5.md)
|
||||||
|
6. [Deploy your app to production](part6.md)
|
||||||
|
|
||||||
1. Get set up and oriented, on this page.
|
## Docker concepts
|
||||||
2. [Build and run your first app](part2.md)
|
|
||||||
3. [Turn your app into a scaling service](part3.md)
|
|
||||||
4. [Span your service across multiple machines](part4.md)
|
|
||||||
5. [Add a visitor counter that persists data](part5.md)
|
|
||||||
6. [Deploy your swarm to production](part6.md)
|
|
||||||
|
|
||||||
The application itself is very simple so that you are not too distracted by
|
Docker is a platform for developers and sysadmins to **develop, deploy, and run**
|
||||||
what the code is doing. After all, the value of Docker is in how it can build,
|
applications with containers. The use of Linux containers to deploy applications
|
||||||
ship, and run applications; it's totally agnostic as to what your application
|
is called _containerization_. Containers are not new, but their use for easily
|
||||||
actually does.
|
deploying applications is.
|
||||||
|
|
||||||
## Prerequisites
|
Containerization is increasingly popular because containers are:
|
||||||
|
|
||||||
While we define concepts along the way, it is good for you to understand
|
- Flexible: Even the most complex applications can be containerized.
|
||||||
[what Docker is](https://www.docker.com/what-docker) before we begin.
|
- Lightweight: Containers leverage and share the host kernel.
|
||||||
|
- Interchangeable: You can deploy updates and upgrades on-the-fly.
|
||||||
|
- Portable: You can build locally, deploy to the cloud, and run anywhere.
|
||||||
|
- Scalable: You can increase and automatically distribute container replicas.
|
||||||
|
- Stackable: You can stack services vertically and on-the-fly.
|
||||||
|
|
||||||
We also need to assume you are familiar with a few concepts before we continue:
|
{:width="300px"}
|
||||||
|
|
||||||
- IP Addresses and Ports
|
### Images and containers
|
||||||
- Virtual Machines
|
|
||||||
- Editing configuration files
|
|
||||||
- Basic familiarity with the ideas of code dependencies and building
|
|
||||||
- Machine resource usage terms, like CPU percentages, RAM use in bytes, etc.
|
|
||||||
|
|
||||||
Finally, though we remind you again when you need these things, you can
|
A container is launched by running an image. An **image** is an executable
|
||||||
save yourself some distraction at that time by [signing up for a
|
package that includes everything needed to run an appplication--the code, a
|
||||||
Docker ID](https://cloud.docker.com) and using it on your local machine
|
runtime, libraries, environment variables, and configuration files.
|
||||||
by running the following command:
|
|
||||||
|
|
||||||
```
|
A **container** is a runtime instance of an image--what the image becomes in
|
||||||
docker login
|
memory when executed (that is, an image with state, or a user process). You can
|
||||||
```
|
see a list of your running containers with the command, `docker ps`, just as you
|
||||||
|
would in Linux.
|
||||||
|
|
||||||
## A brief explanation of containers
|
### Containers and virtual machines
|
||||||
|
|
||||||
An **image** is a lightweight, stand-alone, executable package that includes
|
A **container** runs _natively_ on Linux and shares the kernel of the host
|
||||||
everything needed to run a piece of software, including the code, a runtime,
|
machine with other containers. It runs a discrete process, taking no more memory
|
||||||
libraries, environment variables, and config files.
|
than any other executable, making it lightweight.
|
||||||
|
|
||||||
A **container** is a runtime instance of an image—what the image becomes
|
By contrast, a **virtual machine** (VM) runs a full-blown "guest" operating
|
||||||
in memory when actually executed. It runs completely isolated from the host
|
system with _virtual_ access to host resources through a hypervisor. In general,
|
||||||
environment by default, only accessing host files and ports if configured to do
|
VMs provide an environment with more resources than most applications need.
|
||||||
so.
|
|
||||||
|
|
||||||
Containers run apps natively on the host machine's kernel. They have better
|
{:width="300px"} | {:width="300px"}
|
||||||
performance characteristics than virtual machines that only get virtual access
|
|
||||||
to host resources through a hypervisor. Containers can get native access, each
|
|
||||||
one running in a discrete process, taking no more memory than any other
|
|
||||||
executable.
|
|
||||||
|
|
||||||
## Containers vs. virtual machines
|
## Prepare your Docker environment
|
||||||
|
|
||||||
Consider this diagram comparing virtual machines to containers:
|
Install a [maintained version](https://docs.docker.com/engine/installation/#updates-and-patches){: target="_blank" class="_"}
|
||||||
|
of Docker Community Edition (CE) or Enterprise Edition (EE) on a
|
||||||
|
[supported platform](https://docs.docker.com/engine/installation/#supported-platforms){: target="_blank" class="_"}.
|
||||||
|
|
||||||
### Virtual Machine diagram
|
> For full Kubernetes Integration
|
||||||
|
>
|
||||||
|
> - [Kubernetes on Docker for Mac](https://docs.docker.com/docker-for-mac/kubernetes/){: target="_blank" class="_"}
|
||||||
|
is available in
|
||||||
|
[17.12.0-ce Edge](https://docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-17120-ce-mac45-2018-01-05-edge){: target="_blank" class="_"}
|
||||||
|
or higher.
|
||||||
|
> - [Kubernetes on Docker for Windows](https://docs.docker.com/docker-for-windows/kubernetes/){: target="_blank" class="_"}
|
||||||
|
is available in
|
||||||
|
[18.02.0-ce Edge](https://docs.docker.com/docker-for-windows/release-notes/#docker-community-edition-18020-ce-rc1-win50-2018-01-26-edge){: target="_blank" class="_"}
|
||||||
|
or higher.
|
||||||
|
|
||||||

|
[Install Docker](/engine/installation/index.md){: class="button outline-btn"}
|
||||||
|
|
||||||
Virtual machines run guest operating systems—note the OS layer in each
|
|
||||||
box. This is resource intensive, and the resulting disk image and application
|
|
||||||
state is an entanglement of OS settings, system-installed dependencies, OS
|
|
||||||
security patches, and other easy-to-lose, hard-to-replicate ephemera.
|
|
||||||
|
|
||||||
### Container diagram
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Containers can share a single kernel, and the only information that needs to be
|
|
||||||
in a container image is the executable and its package dependencies, which never
|
|
||||||
need to be installed on the host system. These processes run like native
|
|
||||||
processes, and you can manage them individually by running commands like `docker
|
|
||||||
ps`—just like you would run `ps` on Linux to see active processes.
|
|
||||||
Finally, because they contain all their dependencies, there is no configuration
|
|
||||||
entanglement; a containerized app "runs anywhere."
|
|
||||||
|
|
||||||
## Setup
|
|
||||||
|
|
||||||
Before we get started, make sure your system has the latest version of Docker
|
|
||||||
installed.
|
|
||||||
|
|
||||||
[Install Docker](/install/index.md){: class="button outline-btn"}
|
|
||||||
<div style="clear:left"></div>
|
<div style="clear:left"></div>
|
||||||
> **Note**: version 1.13 or higher is required
|
|
||||||
|
|
||||||
When you run `docker run hello-world`, look for a response like this:
|
### Test Docker version
|
||||||
> **Note**: You may need to add your user to the `docker` group to call this command without sudo. [Read more](https://docs.docker.com/install/linux/linux-postinstall/)
|
|
||||||
|
|
||||||
> **Note**: If there are networking issues in your setup, `docker run hello-world` may fail to execute successfully. In case you are behind a proxy server and you suspect that it blocks the connection, check the [next part](/get-started/part2/) of the tutorial.
|
Ensure that you have a supported version of Docker:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ docker --version
|
||||||
|
Docker version 17.12.0-ce, build c97c6d6
|
||||||
|
```
|
||||||
|
|
||||||
|
Run `docker version`(without `--`) or `docker info` to view even more details
|
||||||
|
about your docker installation:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ docker info
|
||||||
|
Containers: 0
|
||||||
|
Running: 0
|
||||||
|
Paused: 0
|
||||||
|
Stopped: 0
|
||||||
|
Images: 0
|
||||||
|
Server Version: 17.12.0-ce
|
||||||
|
Storage Driver: overlay2
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note**: To avoid permission errors (and the use of `sudo`), add your user to
|
||||||
|
> the `docker` group. [Read more](https://docs.docker.com/engine/installation/linux/linux-postinstall/){: target="_blank" class="_"}.
|
||||||
|
|
||||||
|
### Test Docker installation
|
||||||
|
|
||||||
|
Test that your installation works by running the simple Docker image,
|
||||||
|
[hello-world](https://hub.docker.com/_/hello-world/){: target="_blank" class="_"}:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ docker run hello-world
|
$ docker run hello-world
|
||||||
|
|
||||||
|
Unable to find image 'hello-world:latest' locally
|
||||||
|
latest: Pulling from library/hello-world
|
||||||
|
ca4f61b1923c: Pull complete
|
||||||
|
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
|
||||||
|
Status: Downloaded newer image for hello-world:latest
|
||||||
|
|
||||||
Hello from Docker!
|
Hello from Docker!
|
||||||
This message shows that your installation appears to be working correctly.
|
This message shows that your installation appears to be working correctly.
|
||||||
|
...
|
||||||
To generate this message, Docker took the following steps:
|
|
||||||
...(snipped)...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Now would also be a good time to make sure you are using version 1.13 or higher. Run `docker --version` to check it out.
|
List the `hello-world` image that was downloaded to your machine:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ docker --version
|
$ docker image ls
|
||||||
Docker version 17.05.0-ce-rc1, build 2878a85
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you see messages like the ones above, you are ready to begin your journey.
|
List the `hello-world` container (spawned by the image), which exits after
|
||||||
|
displaying its message. If it were still running, you would _not_ need the
|
||||||
|
`--all` option:
|
||||||
|
|
||||||
## Conclusion
|
```shell
|
||||||
|
$ docker container ls --all
|
||||||
|
CONTAINER ID IMAGE COMMAND CREATED STATUS
|
||||||
|
54f4984ed6a8 hello-world "/hello" 20 seconds ago Exited (0) 19 seconds ago
|
||||||
|
```
|
||||||
|
|
||||||
The unit of scale being an individual, portable executable has vast
|
## Recap and cheat sheet
|
||||||
implications. It means CI/CD can push updates to any part of a distributed
|
|
||||||
application, system dependencies are not an issue, and resource density is
|
|
||||||
increased. Orchestration of scaling behavior is a matter of spinning up new
|
|
||||||
executables, not new VM hosts.
|
|
||||||
|
|
||||||
This tutorial discusses all of these things, but first let's start with the
|
```shell
|
||||||
basics.
|
## List Docker CLI commands
|
||||||
|
docker
|
||||||
|
docker container --help
|
||||||
|
|
||||||
|
## Display Docker version and info
|
||||||
|
docker --version
|
||||||
|
docker version
|
||||||
|
docker info
|
||||||
|
|
||||||
|
## Excecute Docker image
|
||||||
|
docker run hello-world
|
||||||
|
|
||||||
|
## List Docker images
|
||||||
|
docker image ls
|
||||||
|
|
||||||
|
## List Docker containers (running, all, all in quiet mode)
|
||||||
|
docker container ls
|
||||||
|
docker container ls -all
|
||||||
|
docker container ls -a -q
|
||||||
|
```
|
||||||
|
|
||||||
|
## Conclusion of part one
|
||||||
|
|
||||||
|
Containerization makes [CI/CD](https://www.docker.com/use-cases/cicd){: target="_blank" class="_"} seamless. For example:
|
||||||
|
|
||||||
|
- applications have no system dependencies
|
||||||
|
- updates can be pushed to any part of a distributed application
|
||||||
|
- resource density can be optimized.
|
||||||
|
|
||||||
|
With Docker, scaling your application is a matter of spinning up new
|
||||||
|
executables, not running heavy VM hosts.
|
||||||
|
|
||||||
[On to Part 2 >>](part2.md){: class="button outline-btn" style="margin-bottom: 30px; margin-right: 100%"}
|
[On to Part 2 >>](part2.md){: class="button outline-btn" style="margin-bottom: 30px; margin-right: 100%"}
|
||||||
|
|
Loading…
Reference in New Issue