Difference between revisions of "Docker run"

From wikieduonline
Jump to navigation Jump to search
Tags: Mobile web edit, Mobile edit
 
(46 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
 
<code>[[docker]] run IMAGE|IMAGE_ID </code>
 
<code>[[docker]] run IMAGE|IMAGE_ID </code>
* https://docs.docker.com/engine/reference/run/
+
* https://docs.docker.com/engine/reference/commandline/run/
 +
* <code>[[docker run --help]]</code>
  
  -e (Environment variables)
+
  [[-i]], --interactive                    Keep STDIN open even if not attached
  -d [[dettach]]
+
[[-t]], [[--tty]]                            Allocate a pseudo-TTY
 +
[[-e]] (Environment variables)
 +
  [[--env-file]]
 +
[[-d]] [[dettach]]
 
  [[-v]]
 
  [[-v]]
 
  [[-p]]
 
  [[-p]]
Line 15: Line 19:
 
  [[--privileged]]
 
  [[--privileged]]
 
  --group-add $([[getent]] group docker | cut -d: -f3)
 
  --group-add $([[getent]] group docker | cut -d: -f3)
 +
[[--volume]]
  
 
== Examples ==
 
== Examples ==
* <code>docker run [[alpine]]</code>
+
* <code>[[docker run alpine]]</code>
 
* <code>[[docker run ubuntu]]</code>
 
* <code>[[docker run ubuntu]]</code>
* <code>docker run [[-it]] alpine /bin/sh</code>
+
* <code>[[docker run node]]</code>
 +
* <code>[[docker run -it]] alpine /bin/sh</code>
 +
 
 +
* <code>docker run [[--name]] your-container-name your-gitlab-registry.your-domain.com:[[5050]]/your-project/your-repo:your-tag</code>
 +
* <code>docker run 1231243.dkr.ecr.eu-central-1.amazonaws.com/your-repo:yourimage</code>
 +
 
 +
 
 
* <code>docker run -v NEW_VOLUME_NAE:/path/inside/container -it alpine /bin/sh</code>
 
* <code>docker run -v NEW_VOLUME_NAE:/path/inside/container -it alpine /bin/sh</code>
 
* <code>docker run --name [[zabbix]]-appliance [[-p]] 80:80 -p 10051:10051 [[-d]] zabbix/zabbix-appliance:latest</code>
 
* <code>docker run --name [[zabbix]]-appliance [[-p]] 80:80 -p 10051:10051 [[-d]] zabbix/zabbix-appliance:latest</code>
 +
* <code>[[docker run -p]] [[9200]]:9200 -p [[9600]]:9600 -e "discovery.type=single-node" opensearchproject/[[opensearch]]:1.3.1</code>
 +
* <code>docker run -d --name=[[grafana]] -p 3000:3000 grafana/grafana</code> ([[Docker-compose.yml (Grafana)]])
 
* <code>docker run -it --name [[teamcity]]-server-instance [[-v]] /YOUR_FOLDER_TO_DATA:/data/teamcity_server/datadir -v /YOUR_FOLDER_TO_LOGS:/opt/teamcity/logs -p 8111:8111 jetbrains/teamcity-server</code>
 
* <code>docker run -it --name [[teamcity]]-server-instance [[-v]] /YOUR_FOLDER_TO_DATA:/data/teamcity_server/datadir -v /YOUR_FOLDER_TO_LOGS:/opt/teamcity/logs -p 8111:8111 jetbrains/teamcity-server</code>
 
* <code>docker run [[-p]] [[9000]]:9000 [[minio]]/minio server /data</code>
 
* <code>docker run [[-p]] [[9000]]:9000 [[minio]]/minio server /data</code>
* <code>docker run -d --name=[[grafana]] -p 3000:3000 grafana/grafana</code> ([[Docker-compose.yml (Grafana)]])
+
* <code>[[docker run -d]] --[[log-driver]]=[[journald]] YOUR_CONTAINER</code>
* <code>[[docker run]] -d --[[log-driver]]=[[journald]] YOUR_CONTAINER</code>
 
 
* <code>docker run -d -p 8080:8080 [[nodejs]]/app:latest</code>
 
* <code>docker run -d -p 8080:8080 [[nodejs]]/app:latest</code>
 
  35a35860802541a4f2267c28f3afd7de175731a2c6c80c84e992ce6062f5a9dd
 
  35a35860802541a4f2267c28f3afd7de175731a2c6c80c84e992ce6062f5a9dd
Line 31: Line 43:
 
* <code>docker run --name some-nginx-name -d -p 8080:80 some-content-nginx-image</code>
 
* <code>docker run --name some-nginx-name -d -p 8080:80 some-content-nginx-image</code>
  
* <code>[[docker run]] -d -it --name devtest --mount type=[[bind]],source="$(pwd)"/target,target=/app nginx:latest</code>
+
* <code>[[docker run -d -it]] --name devtest --mount type=[[bind]],source="$(pwd)"/target,target=/app nginx:latest</code>
  
 +
Windows example:
 +
docker run --hostname=localhost --mac-address=02:42:11:11:00:01 --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [[--restart]]=no --label='[[org.opencontainers.image.ref.name]]=ubuntu' --label='[[org.opencontainers]].image.version=23.10' [[--runtime]]=[[runc]] -t -d [[ubuntu:rolling]]
  
[[Logstash]]
+
=== [[Logstash]] ===
 
* <code>docker run --rm -it -v ~/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:7.8.0</code>
 
* <code>docker run --rm -it -v ~/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:7.8.0</code>
  
[[OpenShift]]
+
=== [[OpenShift]] ===
 
  docker run -t -u `id -u` \  
 
  docker run -t -u `id -u` \  
 
     -v $HOME/.ssh/id_rsa:/opt/app-root/src/.ssh/id_rsa:Z \  
 
     -v $HOME/.ssh/id_rsa:/opt/app-root/src/.ssh/id_rsa:Z \  
Line 45: Line 59:
 
     -e OPTS="-v" \  
 
     -e OPTS="-v" \  
 
     registry.redhat.io/[[openshift3]]/ose-ansible:v3.11
 
     registry.redhat.io/[[openshift3]]/ose-ansible:v3.11
 +
 +
 +
docker run wrong_image_name
 +
[[Unable to find image]] 'wrong_image_name:latest' locally
 +
[[docker: Error response from daemon]]: Get "https://registry-1.docker.io/v2/": context deadline exceeded
 +
(Client.Timeout exceeded while awaiting headers).
 +
See 'docker run --help'.
 +
 +
docker run [[socat]]
 +
docker: Error response from daemon: pull access denied for socat, repository does not exist or may require 'docker login': denied: requested access to the
 +
resource is denied.
 +
See 'docker run --help'.
 +
 +
Solution: <code>[[docker run alpine/socat]]</code>
 +
 +
 +
docker: [[unknown server OS]]: .
 +
 +
Solution: start docker
  
 
== Runtime constraints on resources ==
 
== Runtime constraints on resources ==
* <code>-m --memory=""</code>
+
* <code>-m [[--memory]]=""</code>
 
* <code>--[[oom]]-kill-disable=false</code> Whether to disable OOM Killer for the container or not.
 
* <code>--[[oom]]-kill-disable=false</code> Whether to disable OOM Killer for the container or not.
 
* <code>--cpus=0.000</code>
 
* <code>--cpus=0.000</code>
Line 53: Line 86:
  
 
https://medium.com/@oprearocks/how-to-properly-override-the-entrypoint-using-docker-run-2e081e5feb9d
 
https://medium.com/@oprearocks/how-to-properly-override-the-entrypoint-using-docker-run-2e081e5feb9d
  <code>docker run --entrypoint "/bin/ls" debian -al /root</code>
+
  <code>[[docker run --entrypoint]] "/bin/ls" debian -al /root</code>
  <code>docker run -it --entrypoint /usr/bin/redis-cli example/redis --help</code>
+
  <code>[[docker run -it --entrypoint]] /usr/bin/redis-cli example/redis --help</code>
 
   
 
   
  
  
docker run -dit --rm --privileged --name dind docker:[[dind]]
+
<code>docker run -dit --rm --privileged --name dind docker:[[dind]]</code>
 +
 
 +
== Errors ==
 +
* <code>WARNING: The requested image's [[platform]] (linux/[[amd64]]) does not match the detected host platform ([[linux/arm64/v8]]) and no specific platform was requested</code>
 +
* <code>[[failed: port is already allocated.]]</code>
  
 
== Activities ==
 
== Activities ==
Line 69: Line 106:
 
* <code>[[docker pull]]</code>
 
* <code>[[docker pull]]</code>
 
* <code>[[docker build]]</code>
 
* <code>[[docker build]]</code>
* [[dockerd]]
+
* <code>[[dockerd]]</code>
 
* /var/run/[[docker.pid]]
 
* /var/run/[[docker.pid]]
 
* /var/run/[[docker.sock]]
 
* /var/run/[[docker.sock]]
Line 76: Line 113:
 
* <code>[[docker-compose.yml]]</code>
 
* <code>[[docker-compose.yml]]</code>
 
* <code>DOCKER_OPTS="--dns 8.8.8.8"</code>
 
* <code>DOCKER_OPTS="--dns 8.8.8.8"</code>
* [[podmam run]]
+
* <code>[[podman run]]</code>
 +
* <code>[[no basic auth credentials.]]</code>
 +
* <code>[[not found: manifest unknown: Requested image not found.]]</code>
 +
* <code>[[kubectl run]]</code>
 +
* [[URI]]
 +
* [[docker run --cap-add]]
 +
* [[Ctrl + p]] and [[Ctrl + q]]  to [[exit]] without stopping container
  
 
== See also ==
 
== See also ==
 
* {{docker run}}
 
* {{docker run}}
* {{Docker Volumes}}
+
* {{docker start}}
* {{docker}}
 
  
 
[[Category:Containers]]
 
[[Category:Containers]]

Latest revision as of 18:18, 22 February 2024

docker run IMAGE|IMAGE_ID

-i, --interactive                    Keep STDIN open even if not attached
-t, --tty                            Allocate a pseudo-TTY
-e (Environment variables)
--env-file
-d dettach
-v
-p
-w
-u 0
--rm
--name 
--user
--link (deprecated) (See also: Kibana/Install Kibana using docker)
--privileged
--group-add $(getent group docker | cut -d: -f3)
--volume

Examples[edit]

  • docker run --name your-container-name your-gitlab-registry.your-domain.com:5050/your-project/your-repo:your-tag
  • docker run 1231243.dkr.ecr.eu-central-1.amazonaws.com/your-repo:yourimage


  • docker run -v NEW_VOLUME_NAE:/path/inside/container -it alpine /bin/sh
  • docker run --name zabbix-appliance -p 80:80 -p 10051:10051 -d zabbix/zabbix-appliance:latest
  • docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:1.3.1
  • docker run -d --name=grafana -p 3000:3000 grafana/grafana (Docker-compose.yml (Grafana))
  • docker run -it --name teamcity-server-instance -v /YOUR_FOLDER_TO_DATA:/data/teamcity_server/datadir -v /YOUR_FOLDER_TO_LOGS:/opt/teamcity/logs -p 8111:8111 jetbrains/teamcity-server
  • docker run -p 9000:9000 minio/minio server /data
  • docker run -d --log-driver=journald YOUR_CONTAINER
  • docker run -d -p 8080:8080 nodejs/app:latest
35a35860802541a4f2267c28f3afd7de175731a2c6c80c84e992ce6062f5a9dd
  • docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx[1]
  • docker run --name some-nginx-name -d -p 8080:80 some-content-nginx-image

Windows example:

docker run --hostname=localhost --mac-address=02:42:11:11:00:01 --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --restart=no --label='org.opencontainers.image.ref.name=ubuntu' --label='org.opencontainers.image.version=23.10' --runtime=runc -t -d ubuntu:rolling

Logstash[edit]

  • docker run --rm -it -v ~/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:7.8.0

OpenShift[edit]

docker run -t -u `id -u` \ 
   -v $HOME/.ssh/id_rsa:/opt/app-root/src/.ssh/id_rsa:Z \ 
   -v $HOME/ansible/hosts:/tmp/inventory:Z \ 
   -e INVENTORY_FILE=/tmp/inventory \ 
   -e PLAYBOOK_FILE=playbooks/prerequisites.yml \ 
   -e OPTS="-v" \ 
   registry.redhat.io/openshift3/ose-ansible:v3.11


docker run wrong_image_name
Unable to find image 'wrong_image_name:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded 
(Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
docker run socat
docker: Error response from daemon: pull access denied for socat, repository does not exist or may require 'docker login': denied: requested access to the 
resource is denied.
See 'docker run --help'.

Solution: docker run alpine/socat


docker: unknown server OS: .

Solution: start docker

Runtime constraints on resources[edit]

  • -m --memory=""
  • --oom-kill-disable=false Whether to disable OOM Killer for the container or not.
  • --cpus=0.000


https://medium.com/@oprearocks/how-to-properly-override-the-entrypoint-using-docker-run-2e081e5feb9d

docker run --entrypoint "/bin/ls" debian -al /root
docker run -it --entrypoint /usr/bin/redis-cli example/redis --help


docker run -dit --rm --privileged --name dind docker:dind

Errors[edit]

Activities[edit]

  1. Understand the difference between docker start and docker run: https://stackoverflow.com/questions/34782678/difference-between-running-and-starting-a-docker-container. See also runC
  2. Understand Start configuration behavior and restart policy


Related terms[edit]

See also[edit]

  • https://hub.docker.com/_/nginx
  • Advertising: