Skip to content

DockerDev

Dr. Rob Lambert, PhD edited this page Sep 6, 2016 · 25 revisions

Installing and testing Docker

Docker needs Centos7

https://docs.docker.com/engine/installation/linux/centos/

sudo su
# link /var/lib/docker to a place with a lot of space
mkdir /home/docker
ln -s /home/docker /var/lib/docker
curl -fsSL https://get.docker.com/ | sh
service docker start
docker run hello-world
chkconfig docker on
groupadd docker
usermod -aG docker <user_name>
source /opt/KaveToolbox/pro/scripts/KaveEnv.sh
pip install docker-compose
exit # leave sudo, logout completely from your machine including killing vncserver -kill and putty
# then login again from scratch and check you can run docker
groups #should say docker
docker run hello-world

Running an existing image

Starting an ubuntu 16 container running bash.

docker run -it ubuntu:16.04 /bin/bash

Building images

To build your own image, good idea to make a docker file. Docker files are very very simple to work with.

https://docs.docker.com/engine/tutorials/dockerimages/

Here is a simple example of a dockerfile:

# KaveToolbox 2.2.-Beta-Pre on ubuntu 14
FROM ubuntu:14.04
MAINTAINER KAVE <[email protected]>
RUN apt-get update
RUN apt-get install -y wget curl
RUN apt-get install -y python python-dev
RUN wget http://repos:[email protected]/noarch/KaveToolbox/2.2-Beta-Pre/kavetoolbox-installer-2.2-Beta-Pre.sh
RUN /bin/bash kavetoolbox-installer-2.2-Beta-Pre.sh --node

To build an image, then you need a directory containing this file

mkdir some-image-name
cd some-image-name
vi Dockerfile
...
docker build -t 'some-image-name' .

Connecting to a build to debug

During a docker build it will say what the name of the intermediate images are. It will also run in intermediate containers. You should be able to find both the intermediate containers (from the last command) and the intermediate images (from before the last command) these in your docker ps/image list, and then you can run interactively from that image from that point to start debugging.

docker ps -a #find continer name
docker images # find image name
# then either
docker start containername
docker start exec -it containername /bin/bash
# or
docker run -it imagename /bin/bash

Reconnecting to a running or old instance

Maybe you exited your docker container and want to reconnect with a terminal, or maybe you stopped your container or it died unexpectedly

try:

docker ps -a #find the container name
docker start containername
docker exec -it containername /bin/bash

Saving an intermediate state / running image with some logical name

During docker tests you're likely to be in the middle of some container and want to make an image of it to try a few options, or reconnect to the interactive session with different options.

docker ps # find the naem of your running image
docker commit <2137173172> "foo/live-image-name" # commit this image
docker run -it "foo/live-image-name" /bin/bash # run again with different options

http://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container

Connecting to specific ports

https://deis.com/blog/2016/connecting-docker-containers-1/

docker run -it -p hostport:containerport ubuntu:16.04 /bin/bash

Cleaning up

Each docker start/build creates potentially several copies of the filesystem in the docker home directory due to snapshotting, this can fill up really really fast, especially with large kavetoolbox installations.

To clean the space out, see:

https://techoverflow.net/blog/2013/10/22/docker-remove-all-images-and-containers/

# kill all containers
docker kill $(docker ps -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)

Because some containers might depend on other containers, some of these steps might not work until you restart docker

sudo service docker restart
# kill all containers
docker kill $(docker ps -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi -f $(docker images -q)

Containers hung forever

Sometimes containers can get totally stuck doing whatever they are doing, this is not very much fun. You can try:

  1. Finding the docker run process and killing it
  2. Running docker kill in a separate terminal
  3. restarting the docker service

pushing a container to dockerhub

https://docs.docker.com/engine/tutorials/dockerrepos/

You will need to know the name of the image locally you want to push abd the name of the remote repository you want to push to.

docker login
docker images #select image name e.g test/example-local-image
docker tag test/example-local-image remotegroup/remote-repository:tag_to_create
docker push remotegroup/remote-repository:tag_to_create

Docker service itself stuck

Try finding the processes in sudo:

sudo su
ps faux | grep docker
kill -9 ...

If this still does not work, restart your machine through the ec2 web interface.

Table of Contents

For users, installers, and other persons interested in the KAVE, or developing solutions on top of a KAVE.

Kave on Azure

For contributors

For someone who modifies the AmbariKave code itself and contributes to this project. Persons working on top of existing KAVEs or developing solutions on top of KAVE don't need to read any of this second part.

Clone this wiki locally