Docker Client Operations: Difference between revisions
Jump to navigation
Jump to search
(108 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
* [[Docker_Concepts#The_Docker_Client|Docker Concepts]] | * [[Docker_Concepts#The_Docker_Client|Docker Concepts]] | ||
* [[Docker Operations#Subjects|Docker Operations]] | * [[Docker Operations#Subjects|Docker Operations]] | ||
=Commands= | |||
{| | |||
| [[docker build|build]] || [[docker create|create]] || [[docker cp|cp]] || [[docker rm|rm]] | |||
|- | |||
| [[docker ps|ps]] || [[docker run|run]] || [[docker stop|stop]] || [[docker rm|rm]] | |||
|- | |||
| [[docker pull|pull]] || [[docker push|push]] || [[docker rmi|rmi]] | |||
|- | |||
| [[docker tag|tag]] || [[docker stack|stack]] | |||
|} | |||
=Installation Verification= | |||
{{Internal|Docker Installation Verification|Docker Installation Verification}} | |||
=Running the Client= | =Running the Client= | ||
Line 27: | Line 43: | ||
==From a Remote Host== | ==From a Remote Host== | ||
=Info= | |||
* <span id='version'></span>Server and client version [[docker version|docker version]] | |||
* System-wide info [[docker info]] | |||
* Low level metadata about an image or container [[docker inspect]] | |||
* Resource statistics for running containers [[docker stats]]. | |||
= | =<span id='Image_Management'></span><span id='images'></span>Image Operations= | ||
==<span id='Image_Registry_Operations'></span>Registry Operations== | |||
= | * <span id='Search_for_Images'></span>Search Docker Hub or other registries: [[docker search]] | ||
* <span id='List_Images'></span>List images in the [[Docker_Concepts#Local_Image_Registry|local registry]]: [[docker images]] | |||
* <span id='Remove_an_Image'></span>Remove images from the [[Docker_Concepts#Local_Image_Registry|local registry]]: [[docker rmi|docker rmi]] | |||
* <span id='Pull_an_Image_from_Registry'></span>Pull an image or a repository from a registry and place it in the local registry: [[docker pull#Overview|docker pull]] | |||
* <span id='Push'></span>Push an image or a repository to a registry: [[docker push#Overview|docker push]] | |||
* <font color=red>'''TODO''': how is a docker instance configured with specific [[Docker Concepts#Image_Registry_Operations|registries]]?</font> | |||
* [[docker tag]] | |||
==<span id='Image_Manipulation'></span>Image Introspection and Manipulation== | |||
= | * <span id='Build'></span><span id='Build_an_Image'></span>Build an image: [[docker build]] | ||
** [[Building a Container that Loops]] | |||
* <span id='Image_Inspect'></span>Obtain low-level metadata about an image: [[docker inspect]] | |||
* <span id='Image_History'></span>Obtain image history: [[docker history]] | |||
* <span id='Image_Save'></span>Save an image into a TAR archive: [[docker save]] | |||
* <span id='load'></span>Load an image from a TAR archive: [[docker load]] | |||
* <span id='Export_the_Filesystem'></span>Export a container's filesystem into a TAR file: [[docker export]] | |||
* <span id='import'></span>Create a new image from a TAR archive: [[docker import|docker import]] | |||
* [[Docker Image Operations - Create a New Image by Writing Over an Existing Image|Create a new image by writing over an existing image]] | |||
= | ===Explore an Image=== | ||
If the image has a shell, it can be run in interactive mode and explored: | If the image has a shell, it can be run in interactive mode and explored: | ||
[[docker run]] -it <''image-id''|''name''> sh | [[docker run]] --rm -it <''image-id''|''name''> bash|sh | ||
While the container is running, the image can be exported into a TAR file system with [[docker export]] and explored off-line. | |||
===Determine the Command that Launches the Process to Be Executed in the Container=== | |||
docker inspect --format '{{.Config.Cmd}}' <''image-id''> | |||
=<span id='Lifecycle'></span><span id='Recipes'></span>Container Lifecycle Operations= | |||
== | * <span id='List_Containers'></span><span id='ps></span>List containers (running or otherwise): [[docker ps#Overview|docker ps]] | ||
* <span id='Create_and_Run_a_New_Container'></span><span id='run'></span>Create and run a new container: [[docker run|docker run]] | |||
* <span id='stop'></span><span id='Stop_a_Container'></span>Stop a running container: [[docker stop#Overview|docker stop]] | |||
* <span id='start'></span><span id='Start_a_Previously_Stopped_Container'></span>Start a previously stopped container: [[docker start#Overview|docker start]] | |||
* <span id='start'></span><span id='Restart_a_Container'></span>Restart a container: [[docker restart#Overview|docker restart]] | |||
* <span id='Remove_a_Container></span>Remove a container: [[docker rm#Overview|docker rm]] | |||
* [[docker - Start a Container Automatically|Start a Container Automatically]] | |||
=Interaction with a Running Container= | |||
= | * [[Docker_exec#Attach_to_a_Running_Container|Attach to a Running Container]]: <span id='exec'></span>[[docker exec|docker exec]] | ||
<span id=' | * <span id='update'></span>[[docker update|docker update]] | ||
* Attach the local standard input, output, and error streams to a running container: <span id='attach'></span>[[docker attach|docker attach]] | |||
* [[Docker Image Operations - Copy Files In and Out of a Container|Copy files in and out of a container]] | |||
= | =Container Introspection= | ||
* <span id='inspect'></span>Low-level information about a container: [[docker inspect|docker inspect]] | |||
* <span id='logs'></span>Look at container's logs [[docker logs|docker logs]] | |||
* Explore changes introduced in the container's file system [[docker diff|docker diff]] | |||
* Resource statistics for running containers [[docker stats]]. | |||
=Network= | |||
{{Internal|Docker Network Operations|Network Operations}} | |||
=Storage= | |||
{{Internal|Docker Storage Operations|Storage Operations}} | |||
== | =Security= | ||
* [[docker login]] | |||
=Scenarios= | |||
{{Internal|Docker Client Scenarios|Docker Client Scenarios}} | |||
=Troubleshooting= | |||
* [[Docker_inspect#Get_the_Reasons_a_Container_Was_Killed_For|Get the Reasons a Container Was Killed For]] |
Latest revision as of 21:10, 16 August 2019
External
- Docker Cheat Sheet: https://github.com/wsargent/docker-cheat-sheet
Internal
Commands
build | create | cp | rm |
ps | run | stop | rm |
pull | push | rmi | |
tag | stack |
Installation Verification
Running the Client
On the Same Host as the Server
In order to connect to the docker server over the Unix socket, the user running the client must have permissions to do so:
[testuser@docker-server ~]$ ls -al /var/run/docker.sock srw-rw----. 1 root docker 0 Apr 25 16:00 /var/run/docker.sock
One way to do that is to make the user a member of "docker" group:
usermod -G docker testuser
From a Remote Host
Info
- Server and client version docker version
- System-wide info docker info
- Low level metadata about an image or container docker inspect
- Resource statistics for running containers docker stats.
Image Operations
Registry Operations
- Search Docker Hub or other registries: docker search
- List images in the local registry: docker images
- Remove images from the local registry: docker rmi
- Pull an image or a repository from a registry and place it in the local registry: docker pull
- Push an image or a repository to a registry: docker push
- TODO: how is a docker instance configured with specific registries?
- docker tag
Image Introspection and Manipulation
- Build an image: docker build
- Obtain low-level metadata about an image: docker inspect
- Obtain image history: docker history
- Save an image into a TAR archive: docker save
- Load an image from a TAR archive: docker load
- Export a container's filesystem into a TAR file: docker export
- Create a new image from a TAR archive: docker import
- Create a new image by writing over an existing image
Explore an Image
If the image has a shell, it can be run in interactive mode and explored:
docker run --rm -it <image-id|name> bash|sh
While the container is running, the image can be exported into a TAR file system with docker export and explored off-line.
Determine the Command that Launches the Process to Be Executed in the Container
docker inspect --format '{{.Config.Cmd}}' <image-id>
Container Lifecycle Operations
- List containers (running or otherwise): docker ps
- Create and run a new container: docker run
- Stop a running container: docker stop
- Start a previously stopped container: docker start
- Restart a container: docker restart
- Remove a container: docker rm
- Start a Container Automatically
Interaction with a Running Container
- Attach to a Running Container: docker exec
- docker update
- Attach the local standard input, output, and error streams to a running container: docker attach
- Copy files in and out of a container
Container Introspection
- Low-level information about a container: docker inspect
- Look at container's logs docker logs
- Explore changes introduced in the container's file system docker diff
- Resource statistics for running containers docker stats.