Install and run docker container on RHEL7

Install docker client and daemon aka engine

yum install -y docker

Start and enable the service

systemctl start docker.service
systemctl enable docker.service

Lets check the version of docker installed

# docker -v
Docker version 1.8.2-el7, build a01dc02/1.8.2

docker version gives us more information

# docker version
Client:
Version: 1.8.2-el7
API version: 1.20
Package Version: docker-1.8.2-10.el7.x86_64
Go version: go1.4.2
Git commit: a01dc02/1.8.2
Built:
OS/Arch: linux/amd64

Server:
Version: 1.8.2-el7
API version: 1.20
Package Version:
Go version: go1.4.2
Git commit: a01dc02/1.8.2
Built:
OS/Arch: linux/amd64

docker info gives us an overview of the host, images and docker itself.

# docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: vg00-docker--pool
Pool Blocksize: 524.3 kB
Backing Filesystem: xfs
Data file:
Metadata file:
Data Space Used: 62.39 MB
Data Space Total: 2.147 GB
Data Space Available: 2.085 GB
Metadata Space Used: 40.96 kB
Metadata Space Total: 37.75 MB
Metadata Space Available: 37.71 MB
Udev Sync Supported: true
Deferred Removal Enabled: true
Library Version: 1.02.107-RHEL7 (2015-10-14)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.0-229.1.2.el7.x86_64
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPUs: 1
Total Memory: 1.791 GiB
Name: myhost.example.com
ID: 5IE4:QSMU:WA4M:WK7C:Y3X7:6BGH:5HA4:3GCD:OJ76:Q3UC:2C4A:VGK7

To run a container, I need to have an image. I don’t have one right now.

# docker images -a
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
#

I will get one

# docker pull rhel7.1
Using default tag: latest
Trying to pull repository registry.access.redhat.com/rhel7.1 ... ^C

Ok, it is trying to pull it from Red Hat’s registry. This is the default setting. I suppose it can be changed. This host does not have direct access to Internet. I am going to have to configure the proxy.

# grep HTTP /etc/sysconfig/docker
HTTP_PROXY='http://proxy.example.com:port'
HTTPS_PROXY='http://proxy.example.com:port'
# systemctl restart docker

Let me pull again

# docker pull rhel7.1
Using default tag: latest
c4f590bbcbe3: Pulling image (latest) from registry.access.redhat.com/rhel7.1, endpoint: https://registry.access.rc4f590bbcbe3: Download complete
Status: Image is up to date for registry.access.redhat.com/rhel7.1:latest

# docker images -a
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry.access.redhat.com/rhel7.1 latest c4f590bbcbe3 12 weeks ago 158.2 MB

Now that I have an image, let me run it. I am using the rhel7.1 image I pulled and I am going to run bash on it.

# docker run -it rhel7.1 /bin/bash
[root@6850658ce592 /]#

There goes my container, “i” for interactive and “t” for a tty.

Here’s the container which I started but no longer running because I exited.

# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6850658ce592 rhel7.1 "/bin/bash" About a minute ago Exited (0) 7 seconds ago condescending_ritchie

I am going start and attach to it using the container ID.

# docker start 6850658ce592
6850658ce592
# docker attach 6850658ce592

[root@6850658ce592 /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@6850658ce592 /]#

And finally I am going to exit and kill this container instance.

# docker rm 6850658ce592
6850658ce592
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s