- Comprehensive Blog on Dockers running on OCI
- running a Docker Container on OCI
- opening OCI Ports for Docker Containers
- Building a Docker Image by using Dockerfile
- Committing changes made in a Docker without using Dockerfile
- Pushing Docker Images to Docker Hub
- DevOps with Github, Docker Hub and Oracle Container Cloud Services
Running Hello World
We will simply pull a hello world image and run it, note each image has an unique id
ubuntu@dockervm:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu@dockervm:~$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world d1725b59e92d: Pull complete Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash ubuntu@dockervm:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB ubuntu@dockervm:~$ docker run -it hello-world Hello from Docker! This message shows that your installation appears to be working correctly.
Running BusyBox Image from hub.docker.com
BusyBox is one of the tinyest images around 1 MB in size and does all that we need to get started,
Create Account and login to hub.docker.com search for Official BusyBox image
Tags are basically different versions of image created by different people , usually latest is what you should prefer
Repo Info gives option to run the image
Using BusyBox we can run some basic linux commands like echo , ls etc , first time it downloads , next time when we run it its running from downloaded local copy so its much faster
ubuntu@dockervm:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB ubuntu@dockervm:~$ docker run busybox:latest echo "Hello Busy Box" Unable to find image 'busybox:latest' locally latest: Pulling from library/busybox 90e01955edcd: Pull complete Digest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812 Status: Downloaded newer image for busybox:latest Hello Busy Box ubuntu@dockervm:~$ docker run busybox:latest echo "Hello Busy Box again" Hello Busy Box again ubuntu@dockervm:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest 59788edf1f3e 4 weeks ago 1.15MB hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB ubuntu@dockervm:~$ docker run busybox:latest ls bin dev etc home proc root sys tmp usr var
Running Dockers in Interactive Mode
When you run docker in interactive mode the changes that you have done is lost once you exit as it spins new container
ubuntu@dockervm:~$ docker run -i -t busybox:latest / # touch newfile.txt / # ls bin dev etc home newfile.txt proc root sys tmp usr var / # exit ubuntu@dockervm:~$ docker run -i -t busybox:latest / # ls bin dev etc home proc root sys tmp usr var / # exit
Check the Currently Running and Previously run Containers
ubuntu@dockervm:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ubuntu@dockervm:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f4d522488e00 busybox:latest "sh" 13 minutes ago Exited (0) 13 minutes ago frosty_keller 6abd29b84824 busybox:latest "sh" 13 minutes ago Exited (0) 13 minutes ago kind_kapitsa 4c0ebd734c27 busybox:latest "ls" 17 minutes ago Exited (0) 17 minutes ago gifted_allen ...
Name the Containers
ubuntu@dockervm:~$ docker run --name Madhusudhan busybox:latest ubuntu@dockervm:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a13c8f04b07b busybox:latest "sh" 5 seconds ago Exited (0) 3 seconds ago Madhusudhan f4d522488e00 busybox:latest "sh" 15 minutes ago Exited (0) 15 minutes ago frosty_keller 6abd29b84824 busybox:latest "sh" 15 minutes ago Exited (0) 15 minutes ago ...
Running Docker in Detached Mode and Inspecting JSON Info
ubuntu@dockervm:~$ docker run -d busybox:latest sleep 100 b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d ubuntu@dockervm:~$ docker inspect b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d [ { "Id": "b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d", "Created": "2018-11-06T11:35:30.799264074Z", "Path": "sleep", "Args": [ "100" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 6596, "ExitCode": 0, "Error": "", "StartedAt": "2018-11-06T11:35:31.267007084Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:59788edf1f3e78cd0ebe6ce1446e9d10788225db3dedcfd1a59f764bad2b2690", "ResolvConfPath": "/var/lib/docker/containers/b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d/resolv.conf", "HostnamePath": "/var/lib/docker/containers/b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d/hostname", "HostsPath": "/var/lib/docker/containers/b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d/hosts", "LogPath": "/var/lib/docker/containers/b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d/b00519b4ab9167fc11879ae21f8c611b8b7b32d07fdcfd4c01a157188853f20d-json.log", "Name": "/jolly_torvalds", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "docker-default", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "GroupAdd": null, "IpcMode": "shareable", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": null, "UTSMode": "", "UsernsMode": "", "ShmSize": 67108864, "Runtime": "runc", "ConsoleSize": [ 0, 0 ], "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": [], "BlkioDeviceReadBps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteIOps": null, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DeviceCgroupRules": null, "DiskQuota": 0, "KernelMemory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": false, "PidsLimit": 0, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0, "MaskedPaths": [ "/proc/acpi", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/proc/scsi", "/sys/firmware" ], "ReadonlyPaths": [ "/proc/asound", "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] }, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/e008c10f28e099496d7fd853b168ee24ae496ceab3177cab9be020e15a3d8665-init/diff:/var/lib/docker/overlay2/69e29060a483a2d26171f0d7f5eb8b4980370c813df45700f38a352d31fa41fb/diff", "MergedDir": "/var/lib/docker/overlay2/e008c10f28e099496d7fd853b168ee24ae496ceab3177cab9be020e15a3d8665/merged", "UpperDir": "/var/lib/docker/overlay2/e008c10f28e099496d7fd853b168ee24ae496ceab3177cab9be020e15a3d8665/diff", "WorkDir": "/var/lib/docker/overlay2/e008c10f28e099496d7fd853b168ee24ae496ceab3177cab9be020e15a3d8665/work" }, "Name": "overlay2" }, "Mounts": [], "Config": { "Hostname": "b00519b4ab91", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "sleep", "100" ], "Image": "busybox:latest", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "NetworkSettings": { "Bridge": "", "SandboxID": "58539676f00c3a50d1688a262dbe3267e02e439f5fd302d81f74ebf778bd3282", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/58539676f00c", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "c14adb9baf592b7a8d3c921d0c170f37da43350bd1d2fa512d15043c3f9e2208", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "MacAddress": "02:42:ac:11:00:02", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "73cdf3fcaf867462cdf3b7f11ef7dd2d1a24d918011f447495419a1ac89534a7", "EndpointID": "c14adb9baf592b7a8d3c921d0c170f37da43350bd1d2fa512d15043c3f9e2208", "Gateway": "172.17.0.1", "IPAddress": "172.X.0.X", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02", "DriverOpts": null } } } } ]