I’m playing around with docker containers, I just wanted to build a
docker container and run a service on it which will be accessible externally.
Lets start by getting a fresh ubuntu image from the repos.
Lets see what images are now available, you should see the latest download in the list.
You see this. We’ll pick the newest one.
|
root@zeus:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ccc7a11d65b1 4 weeks ago 120MB ubuntu 14.06 2a05d9f50082 5 weeks ago 231MB ubuntu <none> 14f60031763d 7 weeks ago 120MB hello-world latest 1815c82652c0 2 months ago 1.84kB |
Now this is how we select the image and open the ports, see the “-p” switches? This will open SSH (22) and Web (80).
|
docker run -i -t -p 22 -p 80 ccc7a11d65b1 /bin/bash |
This will build the container, once your at the logon prompt you will need to install the services, ie
This will update apt and install apache and ssh
|
apt-get update apt-get install openssh-server apache2 |
This will start the services.
|
/etc/init.d/apache2 start /etc/init.d/ssh start |
This will enable the services to start at startup.
|
update-rc.d ssh enable update-rc.d apache2 enable |
Now the container is setup we can exit out.
Once we have exited we’ll start the container.
Now we need to find out if the container is running, and if its running which random ports its assigned to our services.
That command will display the following.
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 82389fa65e87 ccc7a11d65b1 "/bin/bash" 41 minutes ago Up 7 minutes 0.0.0.0:32781->22/tcp, 0.0.0.0:32780->80/tcp webservice01 |
Now the above output tells us the container is running and it has assigned ports to out services. So if you put up the webbrowser on your computer and put the hosts IP in like this,
Now you should see the apache test page.
or is you want to ssh into the container enter this command
|
ssh g33k@10.1.1.100 -p 32781 |
Just name sure you setup a user account on the container first.