Docker in docker on AWS Elastic Beanstalk

I have a docker container running on elastic beanstalk. From within this container I want to run other containers using the docker daemon running on the host OS.

As I read here, it is possible if the first container is invoked by:

  • Update a Docker Image on an EC2 Instance
  • AWS UDP High Availability
  • Kubernetes 1.2alpha8 AWS Container Registry Integration
  • Connection refused with kubectl on EC2 ubuntu instance?
  • Point different domains to different Docker containers on a single EC2 instance?
  • Docker on RHEL 7 in AWS can’t pull images
  • docker run -it -v /var/run/docker.sock:/var/run/docker.sock <image_name>

    Can I make Beanstalk invoke my container is such way?

  • Can't ping docker IPv6 container
  • Running the index structure creator command in an Elasticsearch Docker
  • ClassNotFoundException when submitting yamr job to remote cluster
  • dpkg: docker-ce: dependency problems, but removing anyway as you requested: nvidia-docker
  • Does docker still doesn't run on virtual servers hosted by starto now?
  • process exit code 127 while running a bash script by java service in docker
  • 2 Solutions collect form web for “Docker in docker on AWS Elastic Beanstalk”

    Yes, its possible, but YMMV. Here’s a rundown: allows you to map arbitrary paths into your container path. So, you can map your hosts’s /var/run (which contains docker.sock) into a temp path. Here are the steps:

    Make sure you’ve got a staging directory

    In your dockerfile:

    RUN mkdir /run-data

    Make sure contains it:

        "AWSEBDockerrunVersion": "1",
        "Logging": "/app/log",
        "Volumes": [
                "HostDirectory": "/var/run",
                "ContainerDirectory": "/run-data"

    Then, the /run-data/docker.sock will contain a suitable docker socket for running commands. From this point, you can refer to the docker api and talk to it directly

    Happy docking!

    Unfortunately, Amazon Elastic Beanstalk adopts the policy “one container per VM“, which is fairly limiting.

    There might be a workaround, but it will be a waste of time.

    You shoud use Amazon EC2 if you need to do that.

    You can set up a new instance running Docker in less than 5 minutes!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.