Skip to content

Instantly share code, notes, and snippets.

@ZubairLK
Last active May 15, 2016 09:38
Show Gist options
  • Save ZubairLK/dc6aa744471552df4a96fafcf506a97e to your computer and use it in GitHub Desktop.
Save ZubairLK/dc6aa744471552df4a96fafcf506a97e to your computer and use it in GitHub Desktop.
docker reminder
Ideally, go through https://docs.docker.com/engine/userguide/intro/
Its pretty good and steps through many various features.
Ubuntu repositories usually have an old version.
Install latest from https://docs.docker.com/engine/installation/linux/ubuntulinux/
To make it easy to run docker without sudo. Add current user to sudo.
https://docs.docker.com/engine/installation/linux/ubuntulinux/#create-a-docker-group
Run hello-world container.
docker run hello-world
Run Ubuntu container and bash
docker run -it ubuntu bash
Exit ubuntu by typing exit.
This stops the container.
Run
docker ps
No container running.
Running 'docker run -it ubuntu bash' will start a 'new' container.
If you want to run the same previous container
Run
docker ps -a
zubairlk@zubairlk-linux:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
48b5c757d8e7 ubuntu "bash" 10 seconds ago Exited (0) 3 seconds ago
Using the container id.
docker start 48b5c757d8e7
Then attach to the container
docker attach 48b5c757d8e7
Press enter. You'll be inside bash in the container.
To exit container without killing it,
Press 'CTRL-p CTRL-q'
Docker networking overview is here
https://docs.docker.com/engine/userguide/networking/dockernetworks/
docker run -it ubuntu bash
'CTRL-p CTRL-q'
docker run -it ubuntu bash
'CTRL-p CTRL-q'
docker run -it ubuntu bash
'CTRL-p CTRL-q'
docker run -it ubuntu bash
'CTRL-p CTRL-q'
zubairlk@zubairlk-linux:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc1a1e03913 ubuntu "bash" 4 seconds ago Up 3 seconds big_davinci
8e417d3b2da1 ubuntu "bash" 11 minutes ago Up 11 minutes naughty_leavitt
f8ecdc6e3089 ubuntu "bash" 11 minutes ago Up 11 minutes amazing_mestorf
48b5c757d8e7 ubuntu "bash" 19 minutes ago Up 13 minutes stoic_euclid
zubairlk@zubairlk-linux:~$ docker network inspect bridge
[
{
"Name": "bridge",
"Id": "31915cf374318877680adae2fe92abbd4928dc026035ea02671cffaf5c85698e",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16"
}
]
},
"Internal": false,
"Containers": {
"48b5c757d8e7885ca846b518fc8f1b29c74d8fd8ffb6ba05339cef11e15ce34f": {
"Name": "stoic_euclid",
"EndpointID": "d360c633be394ab5d219ea86d51c9d5aec1f4150510b75d95e82705488bf929b",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
},
"8e417d3b2da1af32e5dc833ff4a3ff6e24f85dc3155cc36731286964579fcc04": {
"Name": "naughty_leavitt",
"EndpointID": "4b5b84c26c160a7085cbc29033fbaab98d4e4bdec45034a42519074341c6ae9e",
"MacAddress": "02:42:ac:11:00:04",
"IPv4Address": "172.17.0.4/16",
"IPv6Address": ""
},
"dfc1a1e03913a164e12b3131b4dfaf61ce6ad523b3a3454f89480dd01f11f93d": {
"Name": "big_davinci",
"EndpointID": "8de2bedba4eb604a2e1197b78cf7a74fcf5f074dff84c712c8e65f4d947f7a94",
"MacAddress": "02:42:ac:11:00:05",
"IPv4Address": "172.17.0.5/16",
"IPv6Address": ""
},
"f8ecdc6e30897f64e4489c90b40c12495ce21b39dc25085ea6bd2512a88f0f05": {
"Name": "amazing_mestorf",
"EndpointID": "2bc9c2a643fb59100288de85e36571065988dfb962724202b05973f44b2c6c34",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
zubairlk@zubairlk-linux:~$
They are all connected to bridge.
You can ping the live containers and their ip addresses.
These containers are very minimal ubuntu and run only bash process.
docker attach a container.
run apt-get update
run apt-get install iputils-ping
Then ping a container from within another container.
Next step Docker volumes. how to manage data sharing etc.
Full doc https://docs.docker.com/engine/userguide/containers/dockervolumes/
Useful part on how to share a folder
https://docs.docker.com/engine/userguide/containers/dockervolumes/#mount-a-host-directory-as-a-data-volume
Basically
docker run -v /Users/<path>:/<container path>
zubairlk@zubairlk-linux:~$ ls sabaq/
command.txt punjab_bio_9th punjab-math-10th_titles.txt video-page.php?sid=punjab-biology-9th-1.1
command.txt~ punjab-biology-10th_titles.txt punjab-math-9th_titles.txt video-page.php?sid=punjab-biology-9th-1.1
dailymotion punjab-biology-9th_titles.txt punjab-physics-10th_titles.txt videos2.txt
dl punjab-chemistry-10th_titles.txt punjab-physics-9th_titles.txt videos.txt
punjab_bio_10th punjab-chemistry-9th_titles.txt sabaq.xml videos.txt~
zubairlk@zubairlk-linux:~$ docker run -v /home/zubairlk/sabaq/:/root/sabaq -it ubuntu bash
root@c224a8059ff3:/# ls /root/
.bashrc .profile sabaq/
root@c224a8059ff3:/# ls /root/sabaq/
command.txt punjab-chemistry-9th_titles.txt sabaq.xml
command.txt~ punjab-math-10th_titles.txt video-page.php?sid=punjab-biology-9th-1.1
dailymotion punjab-math-9th_titles.txt video-page.php?sid=punjab-biology-9th-1.1&v=b-intro-1
dl punjab-physics-10th_titles.txt videos.txt
punjab-biology-10th_titles.txt punjab-physics-9th_titles.txt videos.txt~
punjab-biology-9th_titles.txt punjab_bio_10th videos2.txt
punjab-chemistry-10th_titles.txt punjab_bio_9th
root@c224a8059ff3:/#
/home/zubairlk/sabaq in my host pc is a shared folder now and mapped to /root/sabaq inside container.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment