Kommandos

Aus xinux.net
Zur Navigation springen Zur Suche springen

Allgemeines

Alle Befehle haben die Struktur

docker [Kommando]

Optionen

-b, --bridge=""                        Attach containers to a pre-existing network bridge
-d, --daemon=false                     Enable daemon mode

--dns=[] Force Docker to use specific DNS servers --fixed-cidr="" IPv4 subnet for fixed IPs (e.g. 10.20.0.0/16)

-l, --log-level="info"                 Set the logging level (debug, info, warn, error, fatal)


Kommandos

attach    Attach 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 from a container's filesystem to the host path
create    Create a new container
diff      Inspect changes on a container's filesystem
events    Get real time events from the server
exec      Run a command in a running container
export    Stream the contents of a container as a tar archive
history   Show the history of an image
images    List images
import    Create a new filesystem image from the contents of a tarball
info      Display system-wide information
inspect   Return low-level information on a container or image
kill      Kill a running container
load      Load an image from a tar archive
login     Register or log in to a Docker registry server
logout    Log out from a Docker registry server
logs      Fetch the logs of a container
port      Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
pause     Pause all processes within a container
ps        List containers
pull      Pull an image or a repository from a Docker registry server
push      Push an image or a repository to a Docker registry server
rename    Rename an existing container
restart   Restart a running container
rm        Remove one or more containers
rmi       Remove one or more images
run       Run a command in a new container
save      Save an image to a tar archive
search    Search for an image on the Docker Hub
start     Start a stopped container
stats     Display a live stream of one or more containers' resource usage statistics
stop      Stop a running container
tag       Tag an image into a repository
top       Lookup the running processes of a container
unpause   Unpause a paused container
version   Show the Docker version information
wait      Block until a container stops, then print its exit code

Run

Mit dem Kommando "run" werden Container in Docker ausgeführt

Beispiel:

docker run ubuntu:14.04 /bin/echo 'Hallo Welt'

Syntax:

  • docker -->
  • run --> Kommando zum ausführen eines Containers
  • ubuntu:14.04 -->

Optionen

-a, --attach=[]            Mit STDIN, STDOUT oder STDERR verbinden
-d, --detach=false         Detached mode: den Container im Hintergrund ausführen und neue Container ID anzeigen
--device=[]                eine neue Hostdevice zum Container hinzufügen (z.B. --device=/dev/sdc:/dev/xvdc:rwm)
-e, --env=[]               Umgebungsvariablen setzen
--entrypoint=""            Den Standardeingang des Images überschreiebn
--expose=[]                Einen Port oder einen Portbereich (z.B. --expose=5555-5599) öffnen. Dies wird dem Host nicht mitgeteilt.
-h, --hostname=""          Container host name
-i, --interactive=false    STDIN bleibt geöffnet, auch ohne "attach"
-m, --memory=""            Speicherbegrenzung (RAM) (Format: <Zahl><Einheit>, Einheiten = b, k, m oder g)
--name=""                  Dem Container einen Namen zuweisen
-p, --publish=[]           Dem Host die Ports eines Containers mitteilen
-t, --tty=false            Eine pseudo-TTY zuweisen
-u, --user=""              Username oder UID
-v, --volume=[]            Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)

image herunterladen

docker pull ubuntu:10.04

Syntax:

  • pull: weisst docker an ein image herunterzuladen
  • ubuntu:10.04: name des images (hier Ubuntu 10.04)

image listen

zum anzeigen der vorhandenen images:

docker images

Ausgabe:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               1f80e9ca2ac3        8 days ago          131.5 MB
ubuntu              10.04               3db9c44f4520        10 months ago       183 MB


Optionen

-a, --all=false      Alle Images anzeigen 
-f, --filter=[]      Suchfilter nutzen (z.B., 'dangling=true' um ein hängendes image zu finden)

perstitent starten des containers mit dem namen humppa

  • root@tac:~# docker run -t -i -p 880:80 --name humppa ubuntu:10.04 bash

in der maschine

  • root@64f3a5281e7e:/# cat /etc/issue
Ubuntu 10.04 LTS \n \l
  • root@64f3a5281e7e:/# exit
  • docker start -i ubuntu_persistent
  • docker start -i humppa
humppa
  • root@64f3a5281e7e:/#

apache2 installieren

  • root@64f3a5281e7e:/# apt-get update
  • root@64f3a5281e7e:/# apt-get install apache2
  • root@64f3a5281e7e:/# echo ServerName humppa >> /etc/apache2/apache2.conf
  • root@64f3a5281e7e:/# service apache2 restart

netstat listing

  • root@64f3a5281e7e:/# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -

container verlassen

  • root@64f3a5281e7e:/# exit

wieder auf dem host

  • root@tac:~#

container anzeigen

  • root@tac:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
64f3a5281e7e        ubuntu:10.04        bash                29 minutes ago      Exited (130) 2 seconds ago                       humppa

container löschen

  • root@tac:~# docker rm 64f3a5281e7e
64f3a5281e7e

container verlassen

  • CTRL+P danache CTRL+Q

container wieder betreten

  • root@tac:~# docker attach 64f3a5281e7e

beispiele