Docker in Vagrant issuing : Warning: Connection refused. Retrying

I’ve been try to enable ssh access for Docker’s containers running in Vagrant. I’m almost there. However, I keep getting errors when I run Vagrant up.

Here is my Vagrant file:

  • Build .NET Applications with Docker possible ?
  • sharing docker.sock or docker in docker (dind)
  • Heroku docker deployment
  • How to access mysql outside my kubernetes cluster?
  • Docker ubuntu 16.04 container 64-bit run 32-bit applications
  • How to Copy file to stopped docker container
  • Vagrant.configure("2") do |config|
      config.vm.define "app" do |app|
        app.vm.provider "docker" do |d|
          d.build_dir = "./Docker"
          d.cmd = ["/sbin/init", "--enable-insecure-key"]
          d.has_ssh = true
        end
      end
      config.ssh.username = "root"
      config.ssh.private_key_path = "./insecure_key"
    end
    

    Here is my Dockerfile:

    # Unsecure key
    FROM phusion/baseimage
    
    RUN rm -f /etc/service/sshd/down
    RUN /etc/my_init.d/00_regen_ssh_host_keys.sh
    RUN /usr/sbin/enable_insecure_key
    
    #ADD /home/renato/.ssh/id_rsa.pub /tmp/id_rsa.pub
    #RUN cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys && rm -f /tmp/id_rsa.pub
    
    # Ubuntu
    
    FROM ubuntu:latest
    
    MAINTAINER Tyler Cipriani, tyler@tylercipriani.com
    
    # Download and install php, nginx, and supervisor, hey, just linux for a change!
    RUN apt-get update
    RUN apt-get install -y software-properties-common
    RUN add-apt-repository ppa:nginx/stable
    RUN apt-get update
    RUN apt-get -y dist-upgrade
    RUN apt-get install -y php5-fpm nginx supervisor
    
    # Setup config files
    RUN echo "daemon off;" >> /etc/nginx/nginx.conf
    ADD ./nginx/default /etc/nginx/sites-enabled/default
    ADD ./supervisor/supervisord.conf /etc/supervisor/supervisord.conf
    ADD ./php-fpm/php-fpm.conf /etc/php5/fpm/php-fpm.conf
    
    # Shared volume
    RUN mkdir -p /var/www
    VOLUME ["/var/www"]
    
    # Default command for container, start supervisor
    CMD ["supervisord", "--nodaemon"]
    USER root
    
    # Expose port 80 of the container
    EXPOSE 80
    

    The ssh key I got from here.

    https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key

    Error in my screen:
    enter image description here

    Any help would be really appreciated.

  • Set the docker daemon environment variables on Centos?
  • Error getting container id in jenkins pipeline
  • Cannot install docker pkg dependency in Go
  • Strategies for deciding when to use 'docker run' vs 'docker start' and using the latest version of a given image
  • Udeploy not projecting the data
  • reconfigure timezone inside docker not working
  • One Solution collect form web for “Docker in Vagrant issuing : Warning: Connection refused. Retrying”

    Since you have two FROM directives in your Dockerfile, two different docker images will be built. It seems vagrant sees only the last one (FROM ubuntu:latest) which does not have any ssh service.

    As the phusion/baseimage is itself built from ubuntu:14.04 and as having 2 different docker images is certainly not your goal in this case, you don’t need to have that second FROM instruction in your Dockerfile. Just remove it and give it a try.

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