Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

NOTE: CoreOS installations come with Docker pre-installed. You can skip that step if you already have Docker installed and scroll down to where they start running commands.

Using Docker Images

Pull / Run an Image

Pulling an image will grab it from Docker Hub without running it.

Running an image will pull it if necessary, create a container from it, and start the new container with the given arguments.

Commit any Necessary Changes

Ideally, no changes would be necessary. However, in cases where you need to modify an image you can create a new image from a running container with docker commit.

Push Back to Docker Hub

Once you are satisfied with your changes, you can then choose to push your image back to Docker Hub, so that yourself and others can easily pull and run it in the future!

This is, by far, the easiest way that I've found to pre-package distributable code.

Building Custom Docker Images

Building an Image from a Dockerfile

Once you have a Dockerfile, you can tell docker to build it by running the following command:

Code Block
languagebash
docker build -t tag-name -f path/to/Dockerfile.extension path/to/build/context
i.e.
docker build -t clowder -f ./Dockerfile.clowder .

 

Writing a Dockerfile

Docker images are built from files called Dockerfiles.

A simple Dockerfile example can be found below:

Code Block
# Use centos66 as the base image for this build
FROM    centos:centos6
 
# Enable Extra Packages for Enterprise Linux (EPEL) for CentOS
RUN     yum install -y epel-release
# Install Node.js and npm
RUN     yum install -y nodejs npm
 
# Copy files from the host into the container
COPY package.json /src/package.json
 
# Run 'npm install' to install dependencies
RUN cd /src; npm install --production
 
# Tell Docker we plan to use this port
EXPOSE  8080
 
# Specify the default command for when the container runs
CMD ["node", "/src/index.js"]

 

 

Read up on our Docker workflows here:

Amazing Docker Cheat Sheet

https://github.com/wsargent/docker-cheat-sheet

...

Tips

CoreOS Docker Quirks

Default Docker IP Address

By default, Docker starts the daemon on a 172.17.X.X IP address. This can cause issues if 172.17.X.X is routable on the network from which you are trying to connect. 

...

ip addr should now list your newly specified ip instead of 172.17.x.x. A reboot may also be required in order for this change to take effect.

Command Completion: Unsupported

Bash completion is not available for CoreOS, making it difficult or impossible to install docker command completion, as described here: https://docs.docker.com/compose/completion/

Installing Docker Compose

Since the /usr/local/bin/ folder is read-only, and sudo -i did not seem to help, I was able to install docker-compose by using curl to place the executable in my home folder (or any writable folder). Then, simply add docker-compose to the PATH environment variable and give it permission to execute:

...

chmod +x /home/core/docker-compose/docker-compose

Debugging

General

  • docker diff <name or id> - show what files differ from the source image (what changes you have made since running)

Building a Container

  • docker stats <name or id> - shows memory usage / limits
  • docker run <id> - can use the id of incremental build images to boot into the failing state

Running a Container

  • docker events <id> - shows what docker daemon is doing in the background
  • docker inspect <name or id> - inspect a particular container's configuration
  • docker logs <id> - shows the logs of a particular container
  • nsenter - enter a particular namespace

Inspecting a Running Container

  • docker exec -it <name or id> /bin/bash