20151115

Get CONNECTION_REFUSED when connecting to the port that docker exposes

Details

The docker runs apache. However, after starting the docker, I cannot connect to the address

Solution

Forgot to start apache...

start docker machine

docker-machine start default

when you have started docker machine but are told that docker daemon not running

eval "$(docker-machine env default)"

install java7 on docker

apt-get update && \
apt-get install -y openjdk-7-jdk

run shell from docker

docker run -t -i ubuntu:14.04 /bin/bash

-i means interactive mode

if you want to login to a running container's shell

docker exec -it [container-id] bash

run with port mapping

docker run -d -i -t -p 8000:8000 ubuntu /bin/bash

Commit docker change

If you want to persist the data and programs in a running container, you can use docker commit to do so:

docker commit container_id image_name

the image_name should be of an existing image.

Rename a docker image

docker tag image_id myname/server:latest

List all docker images.

docker images

List all docker processes.

docker ps
docker ps -a // lists all the processes, even if terminated

Install pip on ubuntu

sudo apt-get install python-pip

Install django of a specific version

pip install Django==1.8.6

How to run a docker with port mapping and how to access it

docker run -it -p 55555:80 ubuntu_apache /bin/bash

The above command will run the docker image 'ubuntu_apache' with port mapping 55555(host) to 80(docker). Also, in order to prevent it from exiting immediately, we use -i to run the /bin/bash in interactive mode.

To access it, we need to first find the ip address of docker by

echo $DOCKER_HOS

why not access it with 'localhost:55555'? That is because docker runs in a virtual machine on mac, and the ip of virtual machine is not 'localhost', but '$DOCKER_HOST'.

How to create dockerfile

Use -y to assume 'yes' to all the options

How to save image in a separate file

docker save --output repo.tar ubuntu

And load

docker load --input repo.tar

Lesson learned

When you change the system-level configurations (especially network configurations), remember what you changed. In this case, you can revert the changes if you encounter a non-fixable error.

Recursively chmod

chmod -R 777 $dir

What is service? What is daemon? What is the difference?

A Linux service is an application (or set of applications) that runs in the background waiting to be used, or carrying out essential tasks.

source

What is runlevel?

And what is a runlevel? You might assume that this refers to different levels that the system goes through during a boot up.

source

git checkout vs git clone

To sum it up, clone is for fetching repositories you don't have, checkout is for switching between branches in a repository you already have.

source