Using docker behind a proxy on an EC2 instance - proxy

I'm trying to run docker inside a EC2 VM instance. The instance is behind a http proxy.
As far as I can tell the docker install went okay.
Here is the instance information
Linux ip-X-X-X-X 3.8.0-31-generic #46~precise1-Ubuntu SMP Wed Sep 11 18:21:16 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
The docker version I've is
Docker version 0.6.3, build b0a49a3
When I try to run a simple docker command it hangs for a long time.
$sudo docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu' (tag: latest) locally
Pulling repository ubuntu
I've a feeling that this has something to do with my HTTP proxy settings.
I tried setting proxy in different ways.
For example based on this I tried but it still doesn't work.
$sudo HTTP_PROXY=http://proxy.xyz.com:8080 docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu' (tag: latest) locally
Pulling repository ubuntu
Any idea what am I missing here?

On Amazon Linux, append proxy variables in /etc/sysconfig/docker
export no_proxy='localhost,127.0.0.0/8'
export NO_PROXY='localhost,127.0.0.0/8'
export http_proxy=http://<YOUR_PROXY>:<PROXY_PORT>/
export HTTPS_PROXY=http://<YOUR_PROXY>:<PROXY_PORT>/
export https_proxy=http://<YOUR_PROXY>:<PROXY_PORT>/
export HTTP_PROXY=http://<YOUR_PROXY>:<PROXY_PORT>/
and then restart docker daemon
service docker restart

You need to be running the Docker daemon with your HTTP_PROXY environment variable, since the pulling of images happens through the daemon. If you're on Ubuntu, this can be accomplished by modifying /etc/init/docker.conf.
Update:
We also correctly support /etc/default/docker now, so the best way to accomplish this now (on Ubuntu and Debian) is via export http_proxy=... inside /etc/default/docker.

Something to add to tianon's answer is after modifying the config file don't forget to restart the docker daemon:
sudo service docker restart
to apply the proxy.

Related

Connecting Docker Windows WSL Ubuntu to VMware Ubuntu

I am trying to connect my Windows 10 Home system to be able to run full Linux OS Docker containers. I have installed Docker on both WSL Ubuntu 18.04 as well as a VMware Ubuntu 18.04.
I was trying to follow this guide.
However, I get stuck trying to configure the Daemon as per the instructions.
Can’t use Docker for Windows?
This is only necessary if you are NOT running Docker for Windows!
No problem, just configure your Docker daemon to use -H tcp://0.0.0.0:2375 and --tlsverify=false. Then you can follow along with the rest of this guide exactly.
If you go down this route, I highly recommend rolling your own VM with VMware Player instead of using the Docker Toolbox because VirtualBox has crazy edge case shared folder bugs that will ruin your life at some point. Don’t worry, VMware Player is free. Just Google how to set up Ubuntu 16 server on VMware Player.
When I try to change the Docker Daemon by making a daemon.json file I get errors. I've also tried editing the .profile files and the .bashrc as per other guides (another guide), with no luck.
I am unable to check the DOCKER_HOST variable on the VM Ubuntu.
Don't make things complicated. In your case, why WSL if you just want to connect to a remote daemon? Why not simply use the windows docker client?
Setup you favorite local VM with docker.
Example: I have installed a CentOS distro running on local VMWare Workstation. All Hyper-V of course deinstalled/deactivated.
In this VM, enable tcp access for the daemon.
If you have a systemd linux distro (like mine CentOS), execute this:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo echo '[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375' >> /etc/systemd/system/docker.service.d/options.conf
sudo systemctl daemon-reload
sudo systemctl restart docker`
Test if the port is open with docker info. You should get an API access warning at the bottom result.
Download the Windows docker cli zip from here: https://download.docker.com/win/static/stable/x86_64/
Move the docker.exe to any folder, for ex. your Documents folder.
Then put this folder path into your Windows PATH variable.
Set the docker host: Open PowerShell, execute setx DOCKER_HOST <VM-IP>:2375 and close it.
Open a new PowerShell and call docker info.
You should see the docker and daemon infos.
Do what ever you like now... :-)

How to run docker on the Mac command line?

I have installed docker for a Mac, and in order to execute a simple test I seem to have to run all of these steps:
Run docker-machine start to start the docker daemon(?)
Run docker-machine env to get a list of environment settings.
Run eval $(docker-machine env) to set these settings
Finally you are able to run an example like docker run hello-world
And you have to remember the terminal you run all of these commands, as running the same example from within a different terminal won't work.
Is that the correct way on how you start the daemon or setup the machine/terminal in order to use docker? Or is there a more easy way to do this?
It looks like you have installed Docker Toolbox rather than Docker for Mac.
Once Docker for Mac is installed it provides a more streamlined experience. The Linux VM is largely hidden from you and doesn't require VirtualBox to run.
The docker command will connect to the new VM by default without setting up the environment as the docker socket from the VM is mapped through.
→ ls -l /var/run/docker.sock
lrwxr-xr-x 1 root daemon 57 1 Nov 00:02 /var/run/docker.sock -> /Users/matt/Library/Containers/com.docker.docker/Data/s60

Enable Docker remote API in Mac (Using Docker Quickstart Terminal)

NOTE : I am not using boot2docker
I am trying to enable the docker remote API on my mac. However all the question here are based on using boot2docker. While installing docker on my machine, I followed these steps using the Docker Toolbox and since then I have always used the command bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh' to start docker in my local machine.
I was trying to follow the steps mentioned here, which state that I have to edit the docker.conf file. However I cannot locate the file at all. Any help will be greatly appreciated.
Your remote API should already be available. docker-machine env default will give you the details.
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.56.100:2376"
export DOCKER_CERT_PATH="/Users/jimbob/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
In the end they both use a VirtualBox VM running boot2docker, they are just accessed in different ways.
Any daemon configuration can be done in the /var/lib/boot2docker/profile file if needed.

docker-compose is not working on Docker Beta for OS X

I'm using docker Version 1.11.1-beta11 (build: 6974) on OS X (which is native). It has a fancy migration tool to help you to move images from docker-machine to native docker (or something like that). Everything was working perfect, I even was able to start containers through docker-compose but then I rebooted my laptop and now docker-compose is not recognizing new docker engine I guess because I'm getting:
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
So I believe docker-compose still thinks I'm using or depending on docker-machine to start containers.
Any idea about how to workaround this issue?
Update:
Docker env variables:
DOCKER_TLS_VERIFY=1
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_CERT_PATH=/Users/myuser/.docker/machine/machines/default
DOCKER_MACHINE_NAME=default
I removed the docker env variables from my rc script (~/.zshrc) and upgraded docker-compose version to 1.7.1. Also made sure sure docker-machine was down

How to Setup a Docker Tomcat Container on Mac OS X

I'm new to Docker...
From my understanding, Docker is only compatible with Linux, is it possible to run docker for development purposes on a Mac?
I installed virtualbox using homebrew and have tried to create a virtualbox instance. I installed docker, but am having trouble getting my mac to communicate with the vm docker instance. My end goal is to get a locally debuggable instance of tomcat running on the docker container.
Any help or tips would be helpful.
Information:
Because Docker only runs on Linux you will need to install some kind of virtual instance on your local machine. An easy and popular way to do that is to install
Boot2docker and VirtualBox. VirtualBox is a dependency of Boot2docker. You can download, setup and install the latest versions from their websites or if you are using Homebrew, as you mentioned, you can quickly get the working binaries both in one step.
After installing boot2docker, you're ready to use Boot2docker to create a Tomcat Container. You can find a pre-configured tomcat image by searching Docker's community repository, docker hub registry.
Notes:
Each time you execute the docker run command a new container is created.
The VM running Docker requires a ssh private/public encryption key handshake to connect to. If you follow my steps below, one will be generated for you.
Steps to Setup Tomcat using the tomcat image:
Open Terminal and run this command: brew install boot2docker
Create a new Boot2Docker VM instance using the init command: boot2docker init
Run this command in Terminal to forward local ports to the vm:
for i in {10000..10999}; do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i”; VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";done
Start the boot2docker daemon: boot2docker start or boot2docker up
After starting docker, copy the exports that are displayed from the previous command to your clipboard
Edit your bash profile file ~/.bash_profile (or if you are using zsh, edit the resource configuration file ~/.zshrc) with a text editor (I prefer using Sublime text): subl .zshrc *note: this will permanently save the docker env variables.
Paste the exports into that file and save
Execute the source command on the file: source .zshrc
Pull the latest tomcat image to create a container and start tomcat: docker run -it --rm -p 10080:8080 tomcat:8.0 *note: this will forward your local 10080 port to the vm's 8080 port.
Go to http://localhost:10080, you should see the tomcat start page!
Useful Docker commands:
$ boot2docker status
$ docker version
$ docker ps #shows running containers
$ docker ps -a # shows all containers
$ docker exec -it NAME /bin/bash #to start a bash session on the container. -i = interactive, -t = tty
External Resources:
https://docs.docker.com/installation/mac/#installation
https://registry.hub.docker.com/_/tomcat/
Most people use boot2docker to run on Macs. You may also want to take a look at Kitematic, which gives you a GUI to play with.
Finally, the future is probably to use docker machine, which can provision a VM for you.
Docker requires Linux Kernel features, hence it cannot be run natively on OSX.
See instead Boot2Docker. This link gives you instructions on how to get going.

Resources