Category Archives: Container

19. DevOps:How to upload your docker image to your dockerhub account ?

Docker-logo

How to upload your docker image to your dockerhub account from Ubuntu  ?

In my previous session, we have created the MySQL docker image.

Now let us assume, we need to move into a private registry of dockerhub to save it.

In this exercise we will see:
1. How to use dockerid and tag the image ?
2. How to list the images with dockerid ?
3. How to login to dockerhub with your id ?
4. How to upload your docker image to your docker account and registry ?

Pre-requisites: You need to have your dockerid from https://hub.docker.com/

======>Current mysql images====>
vskumar@ubuntu:~$ sudo docker image ls mysql*
[sudo] password for vskumar:
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
vskumar@ubuntu:~$
==================>

1. How to use dockerid and tag the image ?

My docker id is: vskumardocker
== Using docker id into local variable====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ export DOCKERID=vskumardocker
vskumar@ubuntu:~$ echo $DOCKERID
vskumardocker
vskumar@ubuntu:~$
==================>

= Tagging with dockerid ====>
vskumar@ubuntu:~$ sudo docker image build –tag $DOCKERID/mysql .
ERRO[0301] Can’t add file /home/vskumar/.gnupg/S.gpg-agent to tar: archive/tar: sockets not supported
ERRO[0324] Can’t add file /home/vskumar/.local/share/ubuntu-amazon-default/ubuntu-amazon-default/SingletonSocket to tar: archive/tar: sockets not supported
Sending build context to Docker daemon 808MB
Step 1/2 : FROM mysql
—> 5d4d51c57ea8
Step 2/2 : CMD [“echo”, “This is Mysql done by vskumar for a lab practice of dockerfile”]
—> Using cache
—> 659477c48f0a
Successfully built 659477c48f0a
Successfully tagged vskumardocker/mysql:latest
vskumar@ubuntu:~$
== Tagged mysql image =======>

=== Let us check it ===>
vskumar@ubuntu:~$ sudo docker image ls |more
REPOSITORY TAG IMAGE ID CREATED SIZE
vskumardocker/mysql latest 659477c48f0a 4 weeks ago 374MB
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
== Newly tagged image is there ====>

2. How to list the images with dockerid ?

You can also list the images with dockerid assigned as below:

= How to list the images with dockerid? ====>
vskumar@ubuntu:~$ sudo docker image ls -f reference=”$DOCKERID/*”
REPOSITORY TAG IMAGE ID CREATED SIZE
vskumardocker/mysql latest 659477c48f0a 4 weeks ago 374MB
vskumar@ubuntu:~$
=======>

3. How to login to dockerhub with your id ?

=== Login to dockerhub====>
vskumar@ubuntu:~$ sudo docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don’t have a Docker ID, head over to https://hub.docker.com to create one.
Username: vskumardocker
Password:
Login Succeeded
vskumar@ubuntu:~$
============>

4. How to upload your docker image to your docker account and registry ?

Now, let us use docker push command to push the image to dockerhub:

=== Pushing the image to dockerhub account registry ===>
vskumar@ubuntu:~$ sudo docker image push $DOCKERID/mysql:latest
The push refers to repository [docker.io/vskumardocker/mysql]
12ea28f10d69: Mounted from library/mysql
400836ab4664: Mounted from library/mysql
17d36ba94219: Mounted from library/mysql
d7758e0ab2b0: Mounted from library/mysql
921bf5c178ac: Mounted from library/mysql
3cf1630a511d: Mounted from library/mysql
b80c494a1fdc: Mounted from library/mysql
7b2001677ac9: Mounted from library/mysql
8b452d78b126: Mounted from library/mysql
292c1ee413d0: Mounted from library/mysql
014cf8bfcb2d: Mounted from library/mysql
latest: digest: sha256:09ebaab0035b1955a83646ea41f43a2cd870c934a2255da090918ff7ad37dd0f size: 2621
vskumar@ubuntu:~$
==Note, repository name, TAG should be there correctly ===>

Now, we can see this image on the web page of the docker account:
===== pushed Image onto dockerhub web page ====>
I found the image on the web page with the below name:
vskumardocker/mysql
public
=====================>

 

 

 

20. DevOps:How to Install docker for Windows 10 and use for containers creation ?

How to Install docker for Windows 10 and use for containers creation ?:

Docker-logo

 In this blog,  I have shown the steps for  docker installation on Windows10 OS.

To install the docker for windows 10 OS, you need to download the docker-install.exe from the below url:

https://github.com/boot2docker/windows-installer/releases/tag/v1.8.0

 I have copied all the screens below, while doing my installation.  

You can follow the same.

Docker-Win10-install-screens.jpg

Check on your desktop for boot2docker icon.

You can also install docker toolbox as below:

Dockertoolbox-steps.jpg

Now, go to your Boot2Dcoker icon on your desktop.

Double Click on it.

In the following screens you can see with its start process.

Start-Bootdocker-screens.jpg

You can use the below blogs for containers creation.

https://vskumar.blog/2017/11/27/4-devops-how-to-work-with-docker-containers/

https://vskumar.blog/2017/11/28/5-devops-how-to-work-with-docker-images/

https://vskumar.blog/2017/12/12/13-devops-working-with-dockerfile-to-build-apache2-container-2/

2. Graph database/Docker: How to install Neo4j on a docker container? [for Ubuntu 18.04 VM]

Neo4j                                                                                                      Docker-logo

I have shown in this blog/video on the “Installing Neo4j DB on a Docker container using Ubuntu 18.04 VM”.

Through this blog and video, I have demonstrated the below functions:

a) How to install docker on an Ubuntu 18.04 VM?

b) How to create the Neo4j container from the image ?

c) How to use the container for neo4j browser ?

d) How to login and operate the options ?

c) Then how to shutdown the neo4j container ?

On all the above steps, a practiced video is made for your lab practice.

This is attached at the end of this blog.

Step1:
Initially, we need to check whether the prerequisite packages are installed.
To check, perform the following:

sudo apt-get -y install apt-transport-https ca-certificates curl

Step2:
Then, add the docker.com keys to our local keyset:

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –

Step3:
Next, Add the Docker repository to our system (Ubuntu users, I am assuming you have a 64-bit CPU in your VM):

sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

Step4:
Now, we need to work on Preparing the filesystem.
As we planned want need to keep track of the logs and be able to reuse our data, we will need to give the
Docker image some access to our filesystem.
In our home folder [~], let’s create a Neo4j folder and two subfolders named logs and data.
This below script will do it on a Linux platform:
cd ~
mkdir neo4j
cd neo4j
mkdir logs
mkdir data

Enter the above steps in a .sh script.

Step5:
How to Run Neo4j in a Docker container ?:
I need to run the below command;

sudo apt install docker.io

Now, we can run the below long command in a Terminal to run Docker with a Neo4j image.

sudo docker run –rm –publish=7474:7474 –publish=7687:7687 –volume=$HOME/neo4j/data:/data \
–volume=$HOME/neo4j/logs:/logs neo4j:3.1.2

This command triggered some downloading because our local Docker repository does not have the
Neo4j image available in its 3.1.2 version yet.

Ports used by Neo4j are 7474, 7473, and 7687, for the protocols http, https, and bolt, respectively .
In the parameters part, you can see–volume twice.
Its use is to link the folder on the local filesystem to the container filesystem.

Step6:
Providing the port numbers given as parameters were not in use,
the Terminal should display something like this:

Remote interface available at : http://localhost:7474

Now, it denotes our Docker container started for Neo4j.

This informs us that Neo4j is expecting us to connect on port 7474 as usual.
So let us fire our browser and browse to the very same
URL we saw earlier, http://localhost:7474, and go graphing!
(Make sure our data will be persisted on disk.)

Step7:
now, How to stop Docker running your image ?

In order to stop Docker , you need to pass not the name (of the image)
but the identifier of the running container (based on the image).

So, in another Terminal, let us type as follows to know the status of containers:
docker ps

This will list all the containers running, in our case, only one.
So we look at the first column, container_id, and use it as a parameter:
docker stop container_id

You can watch the terminal screen.
Docker container stopped as it should be stopped with this command.

For typical installation procedure of neo4j visit my blog:

https://vskumar.blog/2017/12/08/how-to-install-neo4j-3-2-6-graph-database-on-ubuntu/

 

 

Vcard-Shanthi Kumar V-v3

Advt-course3rd page

18. DevOps: How to create a MySQL docker container ?

Docker-logo

MySql DB docker container:

In this blog I would like to demonstrate the container creation for MYSQL DB.

The following dockerfile code can be used to create the mysqldb container:
I have made this as  group of commands to be executed from Ubuntu CLI.
=== Dockerfile code for MySql DB=====>
sudo docker container run \
–detach \
–name mysqldb \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
mysql:latest
=== To create mysqldb container ====>

=== Screen output ====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker container run \
> –detach \
> –name mysqldb \
> -e MYSQL_ROOT_PASSWORD=my-secret-pw \
> mysql:latest
dcfc16b7fba9075c59035e29a0efed91b7872e5f5cf72c8656afade824651041
vskumar@ubuntu:~$
==== Created mysql =====>

Please note this time, I have not copied the complete display contents.

=== listed ====>
vskumar@ubuntu:~$ sudo docker image ls mysql
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
vskumar@ubuntu:~$

vskumar@ubuntu:~$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dcfc16b7fba9 mysql:latest “docker-entrypoint.s…” 3 minutes ago Up 3 minutes 3306/tcp mysqldb
a5f1ce30c02d swarm “/swarm manage” 11 days ago Restarting (1) 28 seconds ago gracious_bhabha
vskumar@ubuntu:~$
=================>

So we can have the mysql container also running in background currently.

Let us understand the commands/options used for dockerfile syntax:

Using ‘–detach’ command it runs the container in background.
I have given the container name ‘mysqldb’ with ‘–name’ option.
MySql DB needs the root password.
It has been executed with ‘-e’ option.
Since the mysql db image is not available in my current images list,
it pulls it from dockerhub.

You can try to use the same container for your db usage.

17. DevOps: How to identify the docker container ip?

Docker-logo

Please note, every docker container can have an ip once it is activated.

How to get ip of a container ?

We can check the activated container ips through below exercise:
Initially, you need to activate the container using run command.
Then the ip will be assigned from the docker default gateway bridge.

As below you need to do the lab session:

Step-1: Activate the container

vskumar@ubuntu:~$ sudo docker run -i -t ubuntu /bin/bash
root@2f71a66eabae:/# ps
PID TTY TIME CMD
1 pts/0 00:00:00 bash
9 pts/0 00:00:00 ps
root@2f71a66eabae:/# exit
exit
^[[Avskumar@ubuntu:~$ sudo docker run -i -t ubuntu ^C
vskumar@ubuntu:~$ sudo docker run ubuntu /bin/bash

Step-2: Let is check the docker containers:
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
vskumar@ubuntu:~$ sudo docker ps -aq
74943dfce61c
2f71a66eabae
680a896d2c74
a65d0abcfea5

Step-3:Following shows the current docker networks:

vskumar@ubuntu:~$ sudo docker ps -aq
74943dfce61c
2f71a66eabae
680a896d2c74
a65d0abcfea5

vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74943dfce61c ubuntu “/bin/bash” 34 minutes ago Exited (0) 34 minutes ago pedantic_haibt
2f71a66eabae ubuntu “/bin/bash” 34 minutes ago Exited (0) 34 minutes ago suspicious_kepler
680a896d2c74 ubuntu “/bin/bash” 8 hours ago Exited (0) 8 hours ago tender_ramanujan
a65d0abcfea5 ubuntu:16.04 “/bin/bash” 8 hours ago Exited (0) 8 hours ago competent_albattani

Step4: Making a container active:

The IP is assigned to a container with the below activation.
I named the container as container1.

vskumar@ubuntu:~$ sudo docker run -itd –name=container1 ubuntu:16.04
bfb319cdbfe366b369cb089731f614795677ab3ea4f614066596e9cccf17f57f

Step5: Now check the bridge status and the assigned ips of a default bridge to container1:

vskumar@ubuntu:~$ sudo docker network inspect bridge
[
{
“Name”: “bridge”,
“Id”: “c085bc6ae3691b9d8a43e9fc2a26bddc5809e51a4f3c16338143d4bae2d28151”,
“Created”: “2018-03-08T08:28:53.012490299-08:00”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: [
{
“Subnet”: “172.17.0.0/16”,
“Gateway”: “172.17.0.1”
}
]
},
“Internal”: false,
“Attachable”: false,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“bfb319cdbfe366b369cb089731f614795677ab3ea4f614066596e9cccf17f57f”: {
“Name”: “container1”,
“EndpointID”: “9d5abe4df583946342ab36da0fc76a1d3d4c7a1fdaf2766d18b6dea7cd912eb7”,
“MacAddress”: “02:42:ac:11:00:02”,
“IPv4Address”: “172.17.0.2/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”: {}
}
]

vskumar@ubuntu:~$

Step6: Let us use another conatiner [testcontainer2] to active and get the ip:

sudo docker run -itd –name=testcontainer2 ubuntu:16.04

Step7: You can see the current container with the given names also:

vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9ad288448ca ubuntu “/bin/bash” 3 minutes ago Up 3 minutes testcontainer1
bfb319cdbfe3 ubuntu:16.04 “/bin/bash” 9 minutes ago Exited (137) 5 minutes ago container1
74943dfce61c ubuntu “/bin/bash” 45 minutes ago Exited (0) 45 minutes ago pedantic_haibt
2f71a66eabae ubuntu “/bin/bash” About an hour ago Exited (0) 45 minutes ago suspicious_kepler
680a896d2c74 ubuntu “/bin/bash” 8 hours ago Exited (0) 8 hours ago tender_ramanujan
a65d0abcfea5 ubuntu:16.04 “/bin/bash” 8 hours ago Exited (0) 8 hours ago competent_albattani
vskumar@ubuntu:~$ clear

vskumar@ubuntu:~$

Step8: Let us check the its ip for the activated container as below:

vskumar@ubuntu:~$ sudo docker inspect -f “{{ .NetworkSettings.IPAddress }}” d9ad288448ca
172.17.0.2

You can see the ip:172.17.0.2

vskumar@ubuntu:~$ sudo docker ps -a^C
vskumar@ubuntu:~$ sudo docker inspect -f “{{ .NetworkSettings.IPAddress }}” d9ad288448ca^C
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9ad288448ca ubuntu “/bin/bash” 5 minutes ago Up 5 minutes testcontainer1
bfb319cdbfe3 ubuntu:16.04 “/bin/bash” 11 minutes ago Exited (137) 7 minutes ago container1
74943dfce61c ubuntu “/bin/bash” About an hour ago Exited (0) About an hour ago pedantic_haibt
2f71a66eabae ubuntu “/bin/bash” About an hour ago Exited (0) About an hour ago suspicious_kepler
680a896d2c74 ubuntu “/bin/bash” 8 hours ago Exited (0) 8 hours ago tender_ramanujan
a65d0abcfea5 ubuntu:16.04 “/bin/bash” 8 hours ago Exited (0) 8 hours ago competent_albattani

Step9: Now let us use a third container and verify the ip:

vskumar@ubuntu:~$ sudo docker run -itd –name=testcontainer2 ubuntu:16.04
ee5b7978894bc844ae97d7ea893f1c76b99049a4bb71bedfa01d6e9c55e57867

vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee5b7978894b ubuntu:16.04 “/bin/bash” 15 seconds ago Up 13 seconds testcontainer2
d9ad288448ca ubuntu “/bin/bash” 9 minutes ago Up 9 minutes testcontainer1
bfb319cdbfe3 ubuntu:16.04 “/bin/bash” 15 minutes ago Exited (137) 10 minutes ago container1
74943dfce61c ubuntu “/bin/bash” About an hour ago Exited (0) About an hour ago pedantic_haibt
2f71a66eabae ubuntu “/bin/bash” About an hour ago Exited (0) About an hour ago suspicious_kepler
680a896d2c74 ubuntu “/bin/bash” 8 hours ago Exited (0) 8 hours ago tender_ramanujan
a65d0abcfea5 ubuntu:16.04 “/bin/bash” 8 hours ago Exited (0) 8 hours ago competent_albattani

vskumar@ubuntu:~$ sudo docker inspect -f “{{ .NetworkSettings.IPAddress }}” ee5b7978894b
172.17.0.3
vskumar@ubuntu:~$

Step10: Now you can run the inspect command to check the ip for the latest activated container.

This way you will have the ips for the running container.
Please note as long as you keep running these conatiners these ips are valid.
Now if you want to use them for any micro services setup you can do after this procedure.
The docker network will have them shown through the VM browser also.