Difference between revisions of "Docker"

From DUNE
Jump to navigation Jump to search
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
=Notation=
 +
'''All Docker commands below need to be prepended by "sudo docker"'''
 +
 
=Location of Image Files=
 
=Location of Image Files=
  
Line 6: Line 9:
  
 
=Basic Commands=
 
=Basic Commands=
All prepended by "sudo docker":
 
  
 
* images
 
* images
Line 12: Line 14:
 
* ps -a
 
* ps -a
 
* container ls
 
* container ls
 +
* stop [ -t delay ] my_container
 +
 +
The docker system prune command will remove all stopped containers, all dangling images, and all unused networks:
 +
 +
* system prune
 +
 +
=System Configuration=
 +
After configuration changes, a restart is usually needed:
 +
<pre>
 +
sudo service docker restart
 +
# or, the daemon can be started explicitely as follows:
 +
sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &
 +
</pre>
 +
 +
https://upcloud.com/community/tutorials/how-to-configure-docker-swarm/
 +
 +
 +
In firewall/restricted environments, the following needs to be in
 +
the /etc/docker/daemon.json file (put in your specific DNS):
 +
<pre>
 +
{
 +
    "dns":["my.dns.ip.address"]
 +
}
 +
</pre>
 +
 +
This should work, but in some other cases the file /etc/default/docker
 +
may need to be tweaked, specifically the OPTS.
 +
 +
=Pulling from the Repo=
 +
<pre>
 +
pull mediawiki
 +
</pre>
 +
 +
=Examples=
 +
<pre>
 +
run --name some-mediawiki -p 8080:80 -d mediawiki
 +
run --name some-mariadb -e MYSQL_ROOT_PASSWORD=foobar -p 3306:3306 -d mariadb/server
 +
</pre>
 +
 +
To make data managed in the container persistent between runs of the image one may use
 +
the "volume" option e.g.
 +
 +
<pre>
 +
....  -v /my/chosen/folder:/docker/container/inner/location ...
 +
</pre>
 +
 +
=Journal=
 +
<pre>
 +
journalctl -u docker.service
 +
</pre>
 +
 +
=Apache=
 +
<pre>
 +
docker apache image mod_wsgi python 3
 +
</pre>
 +
 +
=The Host IP=
 +
 +
<pre>
 +
/sbin/ip route|awk '/default/ { print $3 }'
 +
</pre>

Latest revision as of 16:55, 2 June 2019

Notation

All Docker commands below need to be prepended by "sudo docker"

Location of Image Files

The contents of the /var/lib/docker directory vary depending on the driver Docker is using for storage. By default this will be aufs but can fall back to overlay, overlay2, btrfs, devicemapper or zfs depending on your kernel support. In most places this will be aufs but the RedHats went with devicemapper.

Basic Commands

  • images
  • rmi (or rmi -f if simple image delete fails)
  • ps -a
  • container ls
  • stop [ -t delay ] my_container

The docker system prune command will remove all stopped containers, all dangling images, and all unused networks:

  • system prune

System Configuration

After configuration changes, a restart is usually needed:

sudo service docker restart
# or, the daemon can be started explicitely as follows:
sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &

https://upcloud.com/community/tutorials/how-to-configure-docker-swarm/


In firewall/restricted environments, the following needs to be in the /etc/docker/daemon.json file (put in your specific DNS):

{
    "dns":["my.dns.ip.address"]
}

This should work, but in some other cases the file /etc/default/docker may need to be tweaked, specifically the OPTS.

Pulling from the Repo

pull mediawiki

Examples

run --name some-mediawiki -p 8080:80 -d mediawiki
run --name some-mariadb -e MYSQL_ROOT_PASSWORD=foobar -p 3306:3306 -d mariadb/server

To make data managed in the container persistent between runs of the image one may use the "volume" option e.g.

....  -v /my/chosen/folder:/docker/container/inner/location ...

Journal

journalctl -u docker.service

Apache

docker apache image mod_wsgi python 3

The Host IP

/sbin/ip route|awk '/default/ { print $3 }'