A Small Ubuntu in a Docker Container

Recently, I wanted to try out a few things around networking in a Docker container environment. What I wanted to have was a simple container I could open a Bash shell in. Turns out that it’s actually quite easy to do. As I wanted to play around with some options, I decided to use a docker-compose yaml file instead of instantiating the container from the command line. So here’s the docker-compose.yml content:

version: "2.3"

services:
  ubuntu:
    image: ubuntu
    container_name: ubuntu
    command: bash -c "tail -f /dev/null"

Yes, it’s really short. After a

docker-compose up -d

one can access a Bash shell running in the container as follows:

docker container exec -it ubuntu bash

The Ubuntu image running in the container is very small and it’s likely that the tools required are not installed. But there’s apt, so everything that is required can be installed from the command line. Here’s an example that installs net-tools and iputils-ping, so one has ifconfig, ping and other network tools:

apt update
apt install net-tools iputils-ping

And that’s all there is to it. Once done, a

docker-compose down

removes the container again, including all changes and program installations. Very nice!