Coder Social home page Coder Social logo

vagrant-docker-baseimages's Introduction

Vagrant-friendly Docker Base Images

Circle CI

A collection of Vagrant-friendly docker base images (published for linux/amd64 and linux/arm64 platforms) along with corresponding Vagrant baseboxes. Something inbetween the official distro base image and puhsion/baseimage, just enough to make it work with Vagrant.

On top of the official distro base image it includes:

  • the vagrant user (password vagrant) with passwordless sudo enabled
  • the vagrant insecure public key in ~/.ssh/authorized_keys
  • sshd running in the foreground

Vagrant Baseboxes

The intended use of the Vagrant-friendly docker base images is to use them as a basebox in your Vagrantfile. These baseboxes simply reference one of the actual docker base images below.

The following baseboxes are currently published on Vagrant Cloud:

Usage

Use the config.vm.box setting to specify the basebox in your Vagrantfile.

For example, run vagrant init tknerr/baseimage-ubuntu-22.04 --minimal to create the Vagrantfile below:

Vagrant.configure(2) do |config|
  config.vm.box = "tknerr/baseimage-ubuntu-22.04"
end

Then, running vagrant up --provider docker should look similar to this:

W:\repo\sample>vagrant up --provider=docker
Bringing machine 'default' up with 'docker' provider...
==> default: Creating the container...
    default:   Name: minimal_default_1441605508
    default:  Image: tknerr/baseimage-ubuntu:22.04
    default: Volume: /w/repo/sample:/vagrant
    default:   Port: 0.0.0.0:2222:22
    default:
    default: Container created: f366398390f6b33f
==> default: Starting container...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 192.168.59.104:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!

Multi-Platform Support

In case you want bring up the docker base images for an architecture different from your host OS you can do that by setting the $DOCKER_DEFAULT_PLATFORM environment variable.

For example, to run the arm64 base image on an amd64 host:

$ DOCKER_DEFAULT_PLATFORM=linux/arm64 vagrant up --povider docker

Or vice versa, to use the amd64 base image:

$ DOCKER_DEFAULT_PLATFORM=linux/amd64 vagrant up --povider docker

Please note: running the base image under an architecture different from your host OS will run the container emulated under QEMU, which might be substantially slower than running the container under the native architecture!

Docker Base Images

In case you want to work with the actual docker base images directly, the following ones (see subdirectories) are available on docker hub (published as multi-arch docker images, supporting linux/amd64 and linux/arm64 platforms):

Usage

You can use it in your Vagrantfile in it's most simple form like this and then run vagrant up:

Vagrant.configure(2) do |config|
  config.vm.provider "docker" do |d|
    d.image = "tknerr/baseimage-ubuntu:22.04"
  end
end

If you want to use provisioners, you need to additionally tell vagrant that this container has ssh enabled:

Vagrant.configure(2) do |config|
  config.vm.provider "docker" do |d|
    d.image = "tknerr/baseimage-ubuntu:22.04"
    d.has_ssh = true
  end

  # use shell and other provisioners as usual
  config.vm.provision "shell", inline: "echo 'hello docker!'"
end

Multi-Platform Support

As an alternative to using the $DOCKER_DEFAULT_PLATFORM environment variable mentioned above, you can also pass the desired --platform directly via the docker provider configuration in your Vagrantfile:

Vagrant.configure(2) do |config|
  config.vm.provider "docker" do |d|
    d.image = "tknerr/baseimage-ubuntu:22.04"
    d.create_args = [ '--platform=linux/arm64' ]
  end
end

Development

Prerequisites

Prerequisites you need to have installed:

  • Docker
  • Vagrant
  • Ruby

Building and Testing

Install bundler dependencies first:

$ bundle install

To build the Docker Base Images for Ubuntu 22.04:

$ bundle exec rake build:docker:base_images PLATFORM=ubuntu-22.04

Run integration tests for the Docker Base Image:

$ bundle exec rake test:docker:base_images PLATFORM=ubuntu-22.04
rspec --format doc --color --tty spec/baseimage_spec.rb

vagrant-friendly docker baseimages
  tknerr/baseimage-ubuntu:22.04 (for amd64)
    is present as a docker image for amd64
    is referenced in a `Vagrantfile` as a docker image
    is not created when I run `vagrant status`
    comes up when I run `vagrant up --no-provision`
    is now shown as running when I run `vagrant status` again
    accepts remote ssh commands via `vagrant ssh -c`
    can be provisioned with a shell script via `vagrant provision`
    is DISTRIB_ID=Ubuntu / DISTRIB_RELEASE=22.04 in lsb-release file
    is running under amd64 architecture
    can be stopped via `vagrant halt`
    can be destroyed via `vagrant destroy`

Finished in 56.74 seconds (files took 0.31354 seconds to load)
11 examples, 0 failuress

In order to build the Vagrant Basebox "wrappers" around it:

$ bundle exec rake build:vagrant:baseboxes PLATFORM=ubuntu-22.04

Run integration tests for the Vagrant Basebox:

$ bundle exec rake test:vagrant:baseboxes PLATFORM=ubuntu-22.04
rspec --format doc --color --tty spec/basebox_spec.rb

vagrant base boxes for the docker baseimages
  tknerr/baseimage-ubuntu-22.04 (running on an amd64 host)
    is referenced in a `Vagrantfile` as a basebox
    can be imported via `vagrant box add`
    comes up via `vagrant up --provider docker`
    creates a docker container for amd64 architecture
    can be destroyed via `vagrant destroy`

Finished in 30.08 seconds (files took 0.61239 seconds to load)
5 examples, 0 failures

Publishing

This is currently done manually, and requires to log in to dockerhub / vagrantcloud interactively.

To publish the docker base image for Ubuntu 22.04 to dockerhub:

$ bundle exec rake publish:docker:base_images PLATFORM=ubuntu-22.04

To publish the corresponding vagrant basebox to vagrantcloud:

$ bundle exec rake publish:vagrant:baseboxes PLATFORM=ubuntu-22.04

Contributing

How to contribute?

  1. fork this repo
  2. create a new branch with your changes
  3. submit a pull request

License

MIT - see the accompanying LICENSE file

vagrant-docker-baseimages's People

Contributors

mexmirror avatar svenbayer avatar tknerr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vagrant-docker-baseimages's Issues

Publish all docker base images with an up-to-date version

All the docker base images published to dockerhub are heavily outdated (4 years old).

Until #17 is solved, I will publish an up-to-date version of the ubuntu-14.04 / 16.04 / 18.04 / 20.04 images manually once more, so they are freshly built with all current security updates included etc.. As we currently don't use date-based tagging, the existing ones will be overwritten for now. This should be fine though, given the potential security issues the 4 year old container images may bring along.

When building Docker image locale-gen is not found.

When building the Ubuntu 16.04 image the step RUN locale-gen en_US.UTF-8 results on my local system (Ubuntu 16.04 64Bit in VmWare Player) to an error.
Step 4/9 : RUN locale-gen en_US.UTF-8 ---> Running in a5d4adb8a261 /bin/sh: 1: locale-gen: not found The command '/bin/sh -c locale-gen en_US.UTF-8' returned a non-zero code: 127

On Stackoverflow it is suggested to install locales first:
docker ubuntu /bin/sh: 1: locale-gen: not found

Failed to connect to bus: No such file or directory on systemd operations

Hello,

I am having problems to use systemd, I suspect is related to dbus.

Here is my Vagrantfile:

Vagrant.configure("2") do |config|
  ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
  config.vm.provider "docker" do |d|
    d.image = "tknerr/baseimage-ubuntu:16.04"
    d.has_ssh = true
    d.create_args = [ "--privileged", "-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro" ]
  end
  config.vm.synced_folder ".", "/vagrant"
end

When I ssh to the box I try to list the units of systemd and I get the following error:

$ vagrant ssh
Last login: Tue Jan 17 13:13:15 2017 from 172.17.0.1
vagrant@d6fa0552baf5:~$ sudo su
root@d6fa0552baf5:/home/vagrant# systemctl list-units
Failed to connect to bus: No such file or directory

Have you seen this issue? Any idea?

Thanks.

Install sudo in base images?

Not sure if it is a good idea, but if it were a traditional VM you would expect that you are not logged in as root and would need to call sudo. Some provisioning scripts might expect that and bluntly call sudo, too.

So would it be a good idea to have sudo pre-installed in the base images?

vagrant up gets error indicatng that docker not supported

Issue
I ran this on 2023-10-10 and vagrant successfully created a docker image.
I ran today on 2023-11-04 and now getting error described below

Environment:

  • Windows 11 Home Edition
  • Vagrant v2.4.0
  • Docker Desktop 4.25.0 (126437)

Vagrantfile Excerpt

Vagrant.configure("2") do |config|
    config.vm.box = "tknerr/baseimage-ubuntu-22.04"
    config.vm.box_version = "1.0.0"
  end

Error Message

vagrant up --provider=docker | tee ./.vagrant/docker.20231104-0845.log 2>&1
Bringing machine 'default' up with 'docker' provider...
==> default: Box 'tknerr/baseimage-ubuntu-22.04' could not be found. Attempting to find and install...
    default: Box Provider: docker
    default: Box Version: >= 0
==> default: Loading metadata for box 'tknerr/baseimage-ubuntu-22.04'
    default: URL: https://vagrantcloud.com/api/v2/vagrant/tknerr/baseimage-ubuntu-22.04
The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Vagrant Cloud, make sure the box is
released.

Name: tknerr/baseimage-ubuntu-22.04
Address: https://vagrantcloud.com/api/v2/vagrant/tknerr/baseimage-ubuntu-22.04
Requested provider: docker (x64)

Additional Information

When I try to add box manually, this is the result:

$ vagrant box add tknerr/baseimage-ubuntu-22.04
==> box: Loading metadata for box 'tknerr/baseimage-ubuntu-22.04'
    box: URL: https://vagrantcloud.com/api/v2/vagrant/tknerr/baseimage-ubuntu-22.04
The box you're attempting to add has no available version that
matches the constraints you requested. Please double-check your
settings. Also verify that if you specified version constraints,
that the provider you wish to use is available for these constraints.

Box: tknerr/baseimage-ubuntu-22.04
Address: https://vagrantcloud.com/api/v2/vagrant/tknerr/baseimage-ubuntu-22.04
Constraints: >= 0
Available versions: 1.0.0

Use gdraheim/docker-systemctl-replacement in all baseimages

I have made quite positive experience with https://github.com/gdraheim/docker-systemctl-replacement so far, and it totally fits the idea of the vagrant-docker-baseimages.

We should add it to all systemd based baseimages in that repo.

  • at least, so that we have a "docker-compatible" systemctl command available
  • I failed replacing the current sshd entrypoint with systemctl as the entrypoint, I could get it working, but sshd started via systemd regularly crashed and I couldn't figure out why -- so that is not working yet and thus the current sshd entrypoint should be kept in the first step
  • for 16.04 and 18.04 use systemctl.py, for 20.04 use systemctl3.py
  • consider pinning to a specific commit so we get stable versions

Let's do that only after #17 has been completed, i.e. with versioning in place so that we still have the older containers (with original systemd) published and available, if someone still needs them

Automate publishing to dockerhub / vagrantcloud

Goal: automate the publishing to dockerhub / vagrantcloud after merge to master.

For now this is still done manually as per the steps in #18 (it was previously covered by automated builds on dockerhub, but that is now a premium feature and so doesn't happen anymore).

Considerations:

  • publish to both via CircleCI
  • double-publish docker images e.g. with "20.04." tag to keep a history and "20.04" tag pointing to the latest date-tagged image (see also how official ubuntu images handle this)
  • consider double-publishing with date-tagged box versions to vagrantcloud too (also here, get inspiration from official ubuntu boxes)
  • on PRs / feature branches the date-tagged images / baseboxes should be built and tested, but not published
  • consider if date-based tagging + publishing after merge to master is good enough, or if we also want publishing on git tag

Make it easier to build and test a single baseimage version only

Currently we always build everything, would be nice if we could build and test them individually (e.g. and :all rake task for everyting, and :16.04, :18.04, etc tasks for the specific versions.

(dropping it here so it is on the feature-wishlist, but have no time to tackle that now)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.