docker

Viewing Docker image contents with a quick run

Snippet

Or, maybe you do want to run a docker instance quickly to see what is in it, unlike otherwise.

# find the docker images you have locally
$ docker images
REPOSITORY                   TAG                          IMAGE ID       CREATED         SIZE
khodsden/coming-soon         3da8af1                      35bdf1f52fcd   9 minutes ago   142MB
khodsden/coming-soon         43488d2                      314cd6408556   9 days ago      142MB
khodsden/coming-soon         94624cc                      3b701e48dd2b   2 weeks ago     142MB
 
# lightly run the container 
docker run --rm -it image-name:tag bash

Viewing Docker Image Contents

Snippet

Okay, so, you want to view the contents of a Docker image. Do not start / run the image to view its contents if you don't know what the contents are.

Instead, use docker create:

The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to STDOUT . This is similar to docker run -d except the container is never started.

# create but don't run the the image
docker create --name="thisisatempname" image:tag 
 
# run export to view the contents, pipe to the tar command in table of contents mode and paginate with less
docker export thisisatempname | tar t | less
 
# clean up 
docker rm thisisatempname

Install different gems in Docker container

Snippet

I have a development environment that is used locally within docker containers, and deployed to a Heroku-like environment, which has a different setup than the local Docker setup. When running locally in Docker containers, I want to install debase and the ruby-debug-ide gems, so that I can use RubyMine locally, but these are not needed when deployed to the development instance. The deployment does not use the Docker / docker-compose files, so I'm okay with having them be local-development specific.

The trick I found was to use groups in the Gemfile.

In my Dockerfile, I'd call out the groups with the --with={groups} arguments:

RUN bundler install --with=development,docker

group :docker do
  gem 'debase'
  gem 'ruby-debug-ide'
end