Base Image for my Docker Containers built off of Phusion's Baseimage-docker
586
Baseimage is a special Docker image that is configured for correct use within Docker containers based on Baseimage-docker from Phusion.
Table of contents
Yet another Docker base image to make it easier to connect to your running Docker instances.
Based on Phusion's excellent baseimage-docker, this Docker base-image features all of the awesome features you've grown to love like working CRON jobs, a SSH server, a lightweight working init system (that actually works!), and more.
Ubuntu is not designed to be run inside Docker. Its init system, Upstart, assumes that it's running on either real hardware or virtualized hardware, but not inside a Docker container. But inside a container you don't want a full system anyway, you want a minimal system. But configuring that minimal system for use within a container has many strange corner cases that are hard to get right if you are not intimately familiar with the Unix system model. This can cause a lot of strange problems.
Baseimage-docker gets everything right. The "Contents" section describes all the things that it modifies.
You can configure the stock ubuntu image yourself from your Dockerfile, so why bother using baseimage-docker?
docker build, allowing you to iterate your Dockerfile more quickly.The first option we provide is to specify SSH keys in an environment variable when starting your Docker instance:
sudo docker run -d -e SSH_KEYS="$(cat ~/.authorized_keys)" michaelholttech/baseimage
On startup of the container, it will add each SSH key found in the SSH_KEYS
environment variable to the $HOME/.ssh/authorized_keys file inside of the container. You'll
then be able to quickly and easily SSH into the Docker instance using your key.
| Name | Required | Description |
|---|---|---|
SSH_KEYS | No | A newline-delimited list of SSH keys in the authorized_keys file format. |
SSH_USER | No (Defaults to root) | The user to set the SSH keys for, generally root. |
This is an even easier way to maintain a Docker instance's authorized_keys file. In our base-image,
we've created a directory for each user called $HOME/.ssh/authorized_keys.d/ which contains the authorized_keys file which is then symlinked back to $HOME/.ssh/authorized_keys. What this means
is that you can easily maintain the authorized_keys file outside of the Docker instance by using
a Docker volume:
sudo docker run -d --name "dockerduck" -v /host/path/to/dockerduck-ssh-keys:/root/.ssh/authorized_keys.d \
michaelholttech/baseimage
Now, simply open /host/path/to/dockerduck-ssh-keys/authorized_keys and add your SSH public keys there:
sudo cat ~/.ssh/authorized_keys > /host/path/to/dockerduck-ssh-keys/authorized_keys
Done! Now just connect to your Docker instance!
Note: environment variables will always overwrite $HOME/.ssh/authorized_keys, so don't mix and match. Use one or the other, not both.
Now that you've added your keys to your Docker instance, you need to know its internal IP address to connect to it. You can use the following command to see your Docker instance IP addresses:
sudo docker inspect -f "{{.NetworkSettings.IPAddress}}" dockerduck
In my case, the IP address is 172.17.0.31, therefore:
Note, you probably have to enable agent-forwarding if you're connecting to a Docker instance hosted on a remote server, as your agent only runs on your local machine and is terminated on your first hop.
docker-ssh toolThis tool is still under development and does not currently work
Looking up the IP of a container and running an SSH command quickly becomes tedious. Luckily, we provide the docker-ssh tool which automates this process. This tool is to be run on the Docker host, not inside a Docker container.
First, install the tool on the Docker host:
curl --fail -L https://raw.githubusercontent.com/MichaelHoltTech/baseimage/master/tools/install-tools.sh -o /tmp/install-tools.sh && \
sudo sh /tmp/install-tools.sh
Then run the tool as follows to login to a container using SSH:
docker-ssh YOUR-CONTAINER-ID
You can lookup YOUR-CONTAINER-ID by running docker ps.
By default, docker-ssh will open a Bash session. You can also tell it to run a command, and then exit:
docker-ssh YOUR-CONTAINER-ID echo hello world
Content type
Image
Digest
sha256:6a27f9949…
Size
125.8 MB
Last updated
almost 11 years ago
docker pull michaelholttech/baseimage