· docker containers

Installing and running Docker on CentOS 6

The initial setup and basic usage of docker is quite simple, nut the when and why to use docker, and what is docker is a bit in depth. I read this article which covers it brilliantly.

Add the EPEL Repository.

Docker installs from the EPEL (Extra Packages for Enterprise Linux) repo, this repo is a community driven repository of ‘non-standard’ packages, so we first need to install this to get Docker.

yum install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Update your system.

As a force of good habit, I always clear the yum cache and apply any package updates, and reboot if necessary.

yum clean all;yum update -y
Install Docker

The docker package is called ‘docker-io’ is CentOS 6 as the name docker was taken a few year back by a GNOME system tray application.

yum -y install docker-io
Start and enable Docker

Now that its installed, lets start the daemon and make sure its starts on boot.

service docker start
chkconfig docker on

#####Get a docker image docker has a search function, so you can search for images, it could be a plain CentOS one, or an Apache built on, there are thousands to chose from

docker search centos
docker pull centos
See your images

You can see what images you have pulled, each image has an ID, and be default, the first 12 characters are shown.

docker images (0f73ae75014f first 12 chars)
docker images --no-trunc=true (full image ID)
Running the container

The -i flag starts an interactive container. The -t flag creates a pseudo-TTY that attaches stdin and stdout. To quit, press, ‘control + p’ then press ‘control + q’

docker run -i -t centos /bin/bash

Running the container in the background To start a container but in the background, is calling a detached state, its the same as above but with a -d flag added.

docker run -i -t -d centos /bin/bash
Kill the container and delete it

To kill the container, you’ll need to grab the container ID using docker ps -a and then run docker rm. You can’t kill a running container, so this must be killed first with docker kill

docker kill 947e96a5e06c
docker rm 947e96a5e06c
  • LinkedIn
  • Tumblr
  • Reddit

Aaron Mehar

Berkshire, UK