- 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
login to https://hub.docker.com/
SSH to Docker VM , login to docker hub using the same login that you use at hub.docker.com to push the image
Last login: Tue Nov 6 16:57:30 2018 from 106.51.108.157 [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE jamessmith73/debian 2.0 75e65a41a95e 37 minutes ago 218MB jamessmith73/debian 1.0 90c1c24a6dd6 About an hour ago 249MB jamessmith73/debian latest 170489bdc17e About an hour ago 249MB tomcat latest ca9e2fccef98 7 days ago 463MB debian latest be2868bebaba 3 weeks ago 101MB busybox latest 59788edf1f3e 5 weeks ago 1.15MB hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB [email protected]:~$ docker login --username=jamessmith73 Password: WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [email protected]:~$ docker push jamessmith73/debian:2.0 The push refers to repository [docker.io/jamessmith73/debian] a58f3f6961d4: Pushed f715ed19c28b: Mounted from library/debian 2.0: digest: sha256:04e9e86a606b09144425312f7a7e7d207f670623f1b2e2aac25466bdf72d0f33 size: 741
Reality Check
General Cleanup & Removing all Docker Images
[email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE jamessmith73/debian 2.0 75e65a41a95e 36 hours ago 218MB jamessmith73/debian 1.0 90c1c24a6dd6 37 hours ago 249MB jamessmith73/debian latest 170489bdc17e 37 hours ago 249MB tomcat latest ca9e2fccef98 9 days ago 463MB debian latest be2868bebaba 3 weeks ago 101MB busybox latest 59788edf1f3e 5 weeks ago 1.15MB hello-world latest 4ab4c602aa5e 2 months ago 1.84kB [email protected]:~$ docker rmi $(docker images -a -q) Untagged: jamessmith73/debian:1.0 Deleted: sha256:90c1c24a6dd6e99fb02a786cba7a7b45d83d18ad8134bda9e59e568b74a07d51 Untagged: tomcat:latest Untagged: [email protected]:1fcb78083a88bc300d9fcb2ecfe4bcf1d20337db9196634c6c7a823bfc4da4ee Deleted: sha256:ca9e2fccef98191f864f50ee803929ccfb72cec0f371b1d369d6a611e03ca122 Deleted: sha256:fbadc1eef16101fe2b1df1e1bd56db461beb2689725316ec9300e4a556a84f33 .... Error response from daemon: conflict: unable to delete 75e65a41a95e (must be forced) - image is being used by stopped container 7001c8f02235 Error response from daemon: conflict: unable to delete 170489bdc17e (must be forced) - image is being used by stopped container 192bd7f7870f .. [email protected]:~$ docker rm $(docker ps -a -f status=exited -q) 7001c8f02235 c8c24ffca1d6 4ecfe884aecf c00aeaaee7ca 192bd7f7870f [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE jamessmith73/debian 2.0 75e65a41a95e 36 hours ago 218MB jamessmith73/debian latest 170489bdc17e 37 hours ago 249MB debian latest be2868bebaba 3 weeks ago 101MB [email protected]:~$ docker rmi jamessmith73/debian:2.0 Untagged: jamessmith73/debian:2.0 Untagged: jamessmith73/[email protected]:04e9e86a606b09144425312f7a7e7d207f670623f1b2e2aac25466bdf72d0f33 Deleted: sha256:75e65a41a95ef72812b3da9345bffc096a3c6f98dd6b40c52ecc6d8742a59661 Deleted: sha256:abddf9505fa6016df18fd3684b1ca40d1bbaaea870b27f254cee448dff87f2cb [email protected]:~$ docker rmi jamessmith73/debian:latest Untagged: jamessmith73/debian:latest Deleted: sha256:170489bdc17e963846ed15a1deed76d165f41d694d8d3d5fe2e93a2e32416a33 Deleted: sha256:f92bde4cb04e3bd1436cb19108787ec98c11942ad14c388319d82ffb22022fab Deleted: sha256:298c3a2ff986e089ee1cbe4a6e7f42a57fa59f763552d5646412021e8cc87555 [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE [email protected]:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [email protected]:~$
Exercise 1 - Create a PHP Docker using Docker file and Update the Source
In this Exercise the goal is to create a simple php file using Dockerfile , then deploy and run it . once this has been done we will update the source code of php and re run the same code
To do that lets go to docker hub and search for a php dockerfile
[email protected]:~$ touch Dockerfile [email protected]:~$ touch welcome.php [email protected]:~$ vi Dockerfile ubun[email protected]:~$ vi welcome.php [email protected]:~$ cat Dockerfile FROM php:7.2-cli COPY . /usr/src/welcomeapp WORKDIR /usr/src/welcomeapp CMD [ "php", "./welcome.php" ] [email protected]:~$ cat welcome.php echo "This is Updated welcome file ! \n " [email protected]:~$ docker build -t welcomeapp . error checking context: 'no permission to read from '/home/ubuntu/.viminfo''. [email protected]:~$ sudo docker build -t welcomeapp . Sending build context to Docker daemon 22.02kB Step 1/4 : FROM php:7.2-cli 7.2-cli: Pulling from library/php f17d81b4b692: Pull complete .... Digest: sha256:417dd4c0f12e5cd3f284b48b5ea6b13d38eda8eacc9008774637df389590d6da Status: Downloaded newer image for php:7.2-cli ---> df1b7c730f91 Step 2/4 : COPY . /usr/src/welcomeapp ---> f9a60fccbe11 Step 3/4 : WORKDIR /usr/src/welcomeapp ---> Running in eb06807e4370 Removing intermediate container eb06807e4370 ---> f7cbf42a4b13 Step 4/4 : CMD [ "php", "./welcome.php" ] ---> Running in 9053d193300a Removing intermediate container 9053d193300a ---> ee06f79d8b26 Successfully built ee06f79d8b26 Successfully tagged welcomeapp:latest ubu[email protected]:~$ docker run -it --rm --name welcomeapp welcomeapp Welcome to the World of Dockers and Containers ! [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE welcomeapp latest ee06f79d8b26 2 minutes ago 367MB php 7.2-cli df1b7c730f91 3 weeks ago 367MB [email protected]:~$ cat welcome.php echo "This is Updated welcome file ! \n " [email protected]:~$ sudo docker build -t welcomeapp . Sending build context to Docker daemon 22.02kB Step 1/4 : FROM php:7.2-cli ---> df1b7c730f91 Step 2/4 : COPY . /usr/src/welcomeapp ---> a09a50bba552 Step 3/4 : WORKDIR /usr/src/welcomeapp ---> Running in d5f2a2c59054 Removing intermediate container d5f2a2c59054 ---> ed9cfb836321 Step 4/4 : CMD [ "php", "./welcome.php" ] ---> Running in baee438ea5cf Removing intermediate container baee438ea5cf ---> b9303c42bc52 Successfully built b9303c42bc52 Successfully tagged welcomeapp:latest ubu[email protected]:~$ docker run -it --rm --name welcomeapp welcomeapp This is Updated welcome file ! [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE welcomeapp latest b9303c42bc52 29 seconds ago 367MB < none > < none > ee06f79d8b26 4 minutes ago 367MB php 7.2-cli df1b7c730f91 3 weeks ago 367MB
Exercise 2 : Create a Web Based PHP App that runs on Apache
The Above Excercise 1 , did run PHP 7 but as a CLI however , in this ex. we will try to run it with Apache Web Server
[email protected]:~$ cat Dockerfile FROM php:7.2-apache COPY welcome.php /var/www/html/ [email protected]:~$ sudo docker build -t welcomewebapp . Sending build context to Docker daemon 23.04kB Step 1/2 : FROM php:7.2-apache 7.2-apache: Pulling from library/php f17d81b4b692: Already exists 376d99d019dc: Already exists 80b3573727f0: Already exists 2c492579cd1f: Already exists 9127acfc108e: Pull complete 475593d953b6: Pull complete 52442c108349: Pull complete 34b7a8ed8171: Pull complete 57b93ed05069: Pull complete 6921825a665b: Pull complete f23b5690e0b1: Pull complete 17bd82b879bf: Pull complete cc9df9220cbc: Pull complete c56ac54bd023: Pull complete 2dfb6e581aee: Pull complete Digest: sha256:05b1ebefd900f762161eb300c7dd061146ec6269b95783b8afe3592795c1d946 Status: Downloaded newer image for php:7.2-apache ---> cf1a377ba77f Step 2/2 : COPY welcome.php /var/www/html/ ---> fb1d0e32f090 Successfully built fb1d0e32f090 Successfully tagged welcomewebapp:latest ubu[email protected]:~$ docker run -d --name welcomewebapp welcomewebapp Digest: sha256:05b1ebefd900f762161eb300c7dd061146ec6269b95783b8afe3592795c1d946 Status: Downloaded newer image for php:7.2-apache ---> cf1a377ba77f Step 2/2 : COPY welcome.php /var/www/html/ ---> fb1d0e32f090 Successfully built fb1d0e32f090 Successfully tagged welcomewebapp:latest ubu[email protected]:~$ docker run -d --name welcomewebapp welcomewebapp 95604fa5f547cc8599524cea93c27d4a3956637491564b0758a9b6abfb22a40b ub[email protected]:~$ curl http://localhost/welcomewebapp/welcome.php curl: (7) Failed to connect to localhost port 80: Connection refused [email protected]:~$ docker run -d -p 80:80 --name welcomewebapp -v "$PWD":/var/www/html php:7.2-apache [email protected]:~$ curl http://localhost/welcome.php This is Updated welcome file ! [email protected]:~$
Exercise 3 : Exposing the Apache Web URL to Public IP
Login to Cloud OCI Dashboard , Access VCN , Security List Related to DockerVM , Edit Security List and Open port 80
Reality Check of having Exposed the Docker Image to Public IP
Exercise 4: Pushing the Image to Docker Hub Repo
[email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE welcomewebapp latest fb1d0e32f090 25 minutes ago 377MB welcomeapp latest b9303c42bc52 44 minutes ago 367MB ee06f79d8b26 About an hour ago 367MB php 7.2-apache cf1a377ba77f 3 weeks ago 377MB php 7.2-cli df1b7c730f91 3 weeks ago 367MB [email protected]:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f9169034b704 php:7.2-apache "docker-php-entrypoi…" 23 minutes ago Up 23 minutes 0.0.0.0:80->80/tcp welcomewebapp2 95604fa5f547 welcomewebapp "docker-php-entrypoi…" 25 minutes ago Up 25 minutes 80/tcp welcomewebapp [email protected]:~$ docker commit f9169034b704 jamessmith73/welcomewebapp:2.0 sha256:67376578dcec2fabe926a0ae20c65ca72fa85b21193e70e6382fec8b44d70f3e [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE jamessmith73/welcomewebapp 2.0 67376578dcec 9 seconds ago 377MB welcomewebapp latest fb1d0e32f090 27 minutes ago 377MB welcomeapp latest b9303c42bc52 About an hour ago 367MB ee06f79d8b26 About an hour ago 367MB php 7.2-apache cf1a377ba77f 3 weeks ago 377MB php 7.2-cli df1b7c730f91 3 weeks ago 367MB [email protected]:~$ docker push jamessmith73/welcomewebapp:2.0 The push refers to repository [docker.io/jamessmith73/welcomewebapp] e2f23a8e83de: Pushed ffe905bce35f: Pushed b45ac0bf6d34: Pushed .. 687dad24bb36: Pushed 237472299760: Pushed 2.0: digest: sha256:878bbe8516371268f217679c4c878a80729080a97c956c9cfd2be2a3a82d8c65 size: 3657 [email protected]:~$
Reality Check access the Docker Hub
Stopping Docker Images and General Cleanup
[email protected]:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f9169034b704 php:7.2-apache "docker-php-entrypoi…" 4 days ago Up 4 days 0.0.0.0:80->80/tcp welcomewebapp2 95604fa5f547 welcomewebapp "docker-php-entrypoi…" 4 days ago Up 4 days 80/tcp welcomewebapp [email protected]:~$ docker stop f9169034b704 f9169034b704 [email protected]:~$ docker stop 95604fa5f547 95604fa5f547 [email protected]:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [email protected]:~$ [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE welcomewebapp latest fb1d0e32f090 4 days ago 377MB php 7.2-apache cf1a377ba77f 3 weeks ago 377MB [email protected]:~$ docker rmi $(docker images -q) Untagged: welcomewebapp:latest Deleted: sha256:fb1d0e32f0904c65e23ae2e7dffa47b3fef0c3b72a7e4038441a7a037eff52c2 Deleted: sha256:dff57112bba2e42ccc9cfc8842ce62f9cf9866dd94203ecaa644cf9a5800d6d5 Untagged: php:7.2-apache Untagged: [email protected]:05b1ebefd900f762161eb300c7dd061146ec6269b95783b8afe3592795c1d946 Deleted: sha256:cf1a377ba77f9a615f1cc14f9eb439363afd51623d216646cf9001f38c4305e9 Deleted: sha256:71a5bb23a5258f10db0916babfdd04b343f8b22faf8a7cb990134e3267fcbca8 ..... [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE [email protected]:~$