Linux/Docker/Docker-Compose: Difference between revisions
No edit summary |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
== Ubuntu testing == | == Ubuntu testing == | ||
* build from Dockerfile | |||
* keep running without task | * keep running without task | ||
* connect to bridge network "lan" | * connect to bridge network "lan" | ||
Line 25: | Line 26: | ||
external: | external: | ||
name: lan | name: lan | ||
</pre> | |||
== Volumes == | |||
<pre> | |||
version: '3' | |||
services: | |||
web: | |||
build: . | |||
volumes: | |||
- /hostfilesystem:/containerfilesystem | |||
</pre> | |||
== Ports / Expose == | |||
* ports = expose to host network (external) | |||
* expose = expose to container network (internal) | |||
* hostport: 8080 | |||
* containerport: 80 | |||
<pre> | |||
version: "3" | |||
services: | |||
wordpress: | |||
image: wordpress | |||
ports: | |||
- "8080:80" | |||
</pre> | |||
<pre> | |||
ports: | |||
- 139:139 | |||
- 445:445 | |||
- 137:137/udp | |||
- 138:138/udp | |||
</pre> | |||
<pre> | |||
ports: | |||
- 127.0.0.1:8000:8000 | |||
</pre> | |||
<pre> | |||
version: '3' | |||
services: | |||
roundcube: | |||
image: robbertkl/roundcube | |||
expose: | |||
- 80 | |||
</pre> | |||
== Autostart == | |||
<pre> | |||
version: '3' | |||
services: | |||
portainer: | |||
image: portainer/portainer | |||
restart: always | |||
ports: | |||
- 127.0.0.1:9000:9000 | |||
volumes: | |||
- /var/run/docker.sock:/var/run/docker.sock | |||
- portainer_data:/data | |||
volumes: | |||
portainer_data: | |||
</pre> | |||
== Devices == | |||
<pre> | |||
version: '3' | |||
services: | |||
mpd: | |||
build: . | |||
ports: | |||
- 6600:6600 | |||
devices: | |||
- /dev/snd:/dev/snd | |||
</pre> | |||
== Run Command == | |||
<pre> | |||
version: '3' | |||
services: | |||
certbot: | |||
image: certbot/certbot:latest | |||
command: ["certbot", "--version"] | |||
</pre> | |||
== Keep container running after command exits == | |||
<pre> | |||
version: '3' | |||
services: | |||
certbot: | |||
image: certbot/certbot:latest | |||
command: tail -f /dev/null | |||
</pre> | </pre> | ||
Line 40: | Line 137: | ||
- NET_ADMIN | - NET_ADMIN | ||
</pre> | </pre> | ||
[[Category:Linux/Docker]] | |||
[[Category:Linux]] |
Latest revision as of 12:57, 26 March 2020
Basics
- https://docs.docker.com/compose/compose-file/
- Frequently used commands:
docker-compose build docker-compose up docker-compose up -d docker-compose stop
Ubuntu testing
- build from Dockerfile
- keep running without task
- connect to bridge network "lan"
version: '3' services: test123: build: . stdin_open: true networks: default: external: name: lan
Volumes
version: '3' services: web: build: . volumes: - /hostfilesystem:/containerfilesystem
Ports / Expose
- ports = expose to host network (external)
- expose = expose to container network (internal)
- hostport: 8080
- containerport: 80
version: "3" services: wordpress: image: wordpress ports: - "8080:80"
ports: - 139:139 - 445:445 - 137:137/udp - 138:138/udp
ports: - 127.0.0.1:8000:8000
version: '3' services: roundcube: image: robbertkl/roundcube expose: - 80
Autostart
version: '3' services: portainer: image: portainer/portainer restart: always ports: - 127.0.0.1:9000:9000 volumes: - /var/run/docker.sock:/var/run/docker.sock - portainer_data:/data volumes: portainer_data:
Devices
version: '3' services: mpd: build: . ports: - 6600:6600 devices: - /dev/snd:/dev/snd
Run Command
version: '3' services: certbot: image: certbot/certbot:latest command: ["certbot", "--version"]
Keep container running after command exits
version: '3' services: certbot: image: certbot/certbot:latest command: tail -f /dev/null
OpenVPN
- "cap_add" = add capabilities (here for changing network settings)
version: '3' services: openvpn: build: . ports: - 1194:1194 cap_add: - NET_ADMIN