docker

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