Здесь показаны различия между двумя версиями данной страницы.
| linux:use-docker [2019/04/07 21:24] | linux:use-docker [2021/02/11 09:21] (текущий) | ||
|---|---|---|---|
| Строка 1: | Строка 1: | ||
| + | ===== Использование docker ===== | ||
| + | По материалам статьи: [[https://www.8host.com/blog/ustanovka-i-ispolzovanie-docker-v-ubuntu-18-04/]]\\ | ||
| + | \\ | ||
| + | ==== Полезные команды docker ==== | ||
| + | <code bash> | ||
| + | docker run -p 80:80 --name web -d httpd | ||
| + | </code> | ||
| + | Запустить образ apache (httpd) с маппингом 80 порта контейнера на 80 порт хоста, и с назначением контейнеру имени web | ||
| + | ----- | ||
| + | <code bash> | ||
| + | docker run -p 80:80 --name web -d -v $PWD/htdocs:/usr/local/apache2/htdocs httpd | ||
| + | </code> | ||
| + | Аналогично предыдущему примеру, но папка $PWD/htdocs локальной машины монтируется в /usr/local/apache2/htdocs контейнера | ||
| + | ----- | ||
| + | <code bash> | ||
| + | docker images | ||
| + | </code> | ||
| + | Показать образы которые есть в системе | ||
| + | ----- | ||
| + | <code bash> | ||
| + | docker cp ./Views/Home/Index.cshtml exampleApp3000:/app/Views/Home/ | ||
| + | </code> | ||
| + | Скопировать файл в/из контейнер | ||
| + | ----- | ||
| + | <code bash> | ||
| + | docker exec -i -t 758fa1da3bba cat /etc/apache2/apache2.conf | ||
| + | #docker exec -i -t <контейнер или его ID> <команда> | ||
| + | #например: | ||
| + | docker exec -t -i 758fa1da3bba /bin/bash | ||
| + | </code> | ||
| + | Выполнить команду в контейнере\\ | ||
| + | Командная строка в контейнере с id=758fa1da3bba (можно использовать в тч имя контейнера) | ||
| + | ----- | ||
| + | <code bash> | ||
| + | docker commit web doweb | ||
| + | </code> | ||
| + | Сохранить образ web с именем doweb локально | ||
| + | ----- | ||
| + | ==== Синтаксис docker ==== | ||
| + | **docker [option] [command] [arguments]**\\ | ||
| + | \\ | ||
| + | <code> | ||
| + | attach  Attach local standard input, output, and error streams to a running container | ||
| + | build Build an image from a Dockerfile | ||
| + | commit  Create a new image from a container's changes | ||
| + | cp Copy files/folders between a container and the local filesystem | ||
| + | create  Create a new container | ||
| + | diff Inspect changes to files or directories on a container's filesystem | ||
| + | events  Get real time events from the server | ||
| + | exec Run a command in a running container | ||
| + | export  Export a container's filesystem as a tar archive | ||
| + | history  Show the history of an image | ||
| + | images  List images | ||
| + | import  Import the contents from a tarball to create a filesystem image | ||
| + | info Display system-wide information | ||
| + | inspect  Return low-level information on Docker objects | ||
| + | kill Kill one or more running containers | ||
| + | load Load an image from a tar archive or STDIN | ||
| + | login Log in to a Docker registry | ||
| + | logout  Log out from a Docker registry | ||
| + | logs Fetch the logs of a container | ||
| + | pause Pause all processes within one or more containers | ||
| + | port List port mappings or a specific mapping for the container | ||
| + | ps List containers | ||
| + | pull Pull an image or a repository from a registry | ||
| + | push Push an image or a repository to a registry | ||
| + | rename  Rename a container | ||
| + | restart  Restart one or more containers | ||
| + | rm Remove one or more containers | ||
| + | rmi Remove one or more images | ||
| + | run Run a command in a new container | ||
| + | save Save one or more images to a tar archive (streamed to STDOUT by default) | ||
| + | search  Search the Docker Hub for images | ||
| + | start Start one or more stopped containers | ||
| + | stats Display a live stream of container(s) resource usage statistics | ||
| + | stop Stop one or more running containers | ||
| + | tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE | ||
| + | top Display the running processes of a container | ||
| + | unpause  Unpause all processes within one or more containers | ||
| + | update  Update configuration of one or more containers | ||
| + | version  Show the Docker version information | ||
| + | wait Block until one or more containers stop, then print their exit codes | ||
| + | </code> | ||
| + | Чтобы получить список опций конкретной подкоманды, введите:\\ | ||
| + | **docker docker-subcommand --help**\\ | ||
| + | \\ | ||
| + | ==== Первый запуск ==== | ||
| + | <code bash> | ||
| + | docker run hello-world | ||
| + | </code> | ||
| + | \\ | ||
| + | Команда должна вернуть следующий результат:\\ | ||
| + | \\ | ||
| + | <code> | ||
| + | Unable to find image 'hello-world:latest' locally | ||
| + | latest: Pulling from library/hello-world | ||
| + | 9bb5a5d4561a: Pull complete | ||
| + | Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d | ||
| + | Status: Downloaded newer image for hello-world:latest | ||
| + | Hello from Docker! | ||
| + | This message shows that your installation appears to be working correctly. | ||
| + | ... | ||
| + | </code> | ||