Docker Tutorial: Difference between revisions
No edit summary |
No edit summary |
||
Line 43: | Line 43: | ||
* [https://hub.docker.com/editions/community/docker-ce-desktop-mac Mac OSX] | * [https://hub.docker.com/editions/community/docker-ce-desktop-mac Mac OSX] | ||
* [https://hub.docker.com/editions/community/docker-ce-desktop-windows Windows] | * [https://hub.docker.com/editions/community/docker-ce-desktop-windows Windows] | ||
=== Create Containers === | |||
==== Basic Creation ==== | |||
This is my go-to recipe for daily container creation: | |||
<syntaxhighlight lang=bash> | |||
# Create the container | |||
docker create -ti --name mycontainer ubuntu:18.04 | |||
</syntaxhighlight> | |||
==== Sharing Host Data With Volumes ==== | |||
Absolute paths refer to dirs or files in the host: | |||
<syntaxhightlight lang=bash> | |||
# Share dir: /home/mgruner (host) in /host (container) | |||
docker create -ti -v /home/mgruner/:/host ubuntu:18.04 | |||
# Share file: /home/mgruner/file.txt (host) in /host.txt (container) | |||
docker create -ti -v /home/mgruner/file.txt:/host.txt ubuntu:18.04 | |||
</syntaxhighlight> | |||
Paths with no slashes create persistent volumes | |||
<syntaxhightlight lang=bash> | |||
# Create a persistent volume | |||
docker create -ti -v myvolume:/host ubuntu:18.04 | |||
</syntaxhighlight> |
Revision as of 21:26, 27 March 2020
<pdf>File:Rr training sesssions docker|frameless|center|Docker Training</pdf>
Commands Quick Reference
Install
On Debian-based systems Docker may be installed via Apt (taken from the official documentation):
# Uninstall old versions sudo apt remove docker docker-engine docker.io containerd runc # Install dependencies sudo apt update sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common # Install GPG Key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # Add Docker PPA sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # Finally install sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io
To run as non-root user:
# Create the docker group sudo groupadd docker # Add yourself to the group sudo usermod -aG docker $USER # To avoid re-logging newgrp docker # Test proper installation docker ps
Other supported OS:
Create Containers
Basic Creation
This is my go-to recipe for daily container creation:
# Create the container docker create -ti --name mycontainer ubuntu:18.04
Sharing Host Data With Volumes
Absolute paths refer to dirs or files in the host: <syntaxhightlight lang=bash>
- Share dir: /home/mgruner (host) in /host (container)
docker create -ti -v /home/mgruner/:/host ubuntu:18.04
- Share file: /home/mgruner/file.txt (host) in /host.txt (container)
docker create -ti -v /home/mgruner/file.txt:/host.txt ubuntu:18.04 </syntaxhighlight>
Paths with no slashes create persistent volumes <syntaxhightlight lang=bash>
- Create a persistent volume
docker create -ti -v myvolume:/host ubuntu:18.04 </syntaxhighlight>