I build my project with following Dockerfile
:
FROM ubuntu:14.04
#"updating package repos.."
RUN apt-get update
#"installing required packages.."
RUN apt-get -y install python2.7-dev build-essential python-pip
run apt-get -y install libjpeg-dev libpng3 libpng12-dev
run apt-get -y install nodejs npm nodejs-legacy
run npm install -g peer
run apt-get -y install supervisor
#"creating sites folder under /opt"
run mkdir /opt/sites
#"copying project into /opt/sites"
add project-latest /opt/sites/project-latest
#"copying supervisor conf into /etc/supervisor/conf.d"
add etc/project.conf /etc/supervisor/conf.d/
#"installing virtualenv"
run pip install virtualenv
#"change working dir to /opt/sites/project-latest"
workdir /opt/sites/project-latest
#"create vritualenv folder named 'env' "
run virtualenv env
#"activating environment"
run . env/bin/activate
#"installing packages into env from requirements.txt"
run pip install -r requirements.txt
#"syncing DB"
run python manage.py syncdb
#"migrating DB"
run python manage.py migrate
#"update and restart supervisorctl"
run service supervisor start
cmd supervisorctl reread
cmd supervisorctl update
cmd supervisorctl restart all
#"expose 8000 and 9000 ports"
expose 8000
expose 9000
And this is the final output of build process:
Successfully built 29dbd8e8bb0a
Removing intermediate container 8a20545921e0
Removing intermediate container 0da63841f6ad
Removing intermediate container fab164fe93c2
Removing intermediate container 77b61eceef36
Removing intermediate container 87a24b079f47
Removing intermediate container cb2520749e30
Removing intermediate container 9e9c54376433
Removing intermediate container 130f6eaeed6a
Removing intermediate container 56f9d93a1e75
Removing intermediate container 599b10008caa
Removing intermediate container eab7598a5e95
Removing intermediate container c31b58fcc405
Removing intermediate container 8b4a55fbb345
Removing intermediate container 13b35d86044e
Removing intermediate container 0ab10eef8f5e
Removing intermediate container ebf42d9493f1
Removing intermediate container 70c772c4aa73
Removing intermediate container fe5039bfbe15
Removing intermediate container 8f9a93cd5438
Removing intermediate container 2d673cf029f8
Removing intermediate container ab8485d09ee7
Removing intermediate container 0fdfa200ac27
Removing intermediate container d2d02358e25d
If I create a container to run bash
inside my built image, I see some of the build steps are forgotten. i.e, there is no virtual environment with my requirements.txt
file.
And I have no idea how to open my running Django
application from my host machine. There are no any ports or IP info either.
By removing a container you remove the resources use to track this layer of changes that the container has done on top of the image. When a container is running it consumes CPU, memory and the HDD space associated with this layer. When a stopped container is removed the HDD space is also freed up.
Its always better to stop the container and then remove it using the remove command. Stopping the container and then removing it will allow sending SIG_HUP signal to recipients. This will ensure that all the containers have enough time to clean up their tasks.
A container is created from a container image. Images are tarballs with a JSON configuration file attached. Images are often nested: for example this Libresonic image is built on top of a Tomcat image that depends (eventually) on a base Debian image.
The most common failures we see when talking to developers using containers are 1) User misconfiguration of containers or applications in those containers. 2) Over-commitment of resources because of a lack of capacity management and planning around containers which is hard to predict.
Removing intermediate images is normal. If you want to keep them you'll have to add --rm=false
to your build command.
There are a couple of problems with your Dockerfile. For starters only the last CMD
will take effect (here are the docs).
Also, this line looks suspicious:
run . env/bin/activate
I guess it's meant to set-up some environment variables, but I don't think that's the way the docker works. I think that either you have to use the ENV
command or you'll have to run this and the following commands together:
run . env/bin/activate; pip install -r requirements.txt; python manage.py syncdb; python manage.py migrate
Regarding the ports, do you run the image with -p
or -P
options?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With