Dockerfile:
FROM shawnzhu/ruby-nodejs:0.12.7
RUN \
apt-get install git \
&& npm install -g bower gulp grunt \
gem install sass
RUN useradd -ms /bin/bash devel
# Deal with ssh
COPY ssh_keys/id_rsa /devel/.ssh/id_rsa
COPY ssh_keys/id_rsa.pub /devel/.ssh/id_rsa.pub
RUN echo "IdentityFile /devel/.ssh/id_rsa" > /devel/.ssh/config
# set root password
RUN echo 'root:password' | chpasswd
# Add gitconfig
COPY .gitconfig /devel/.gitconfig
USER devel
WORKDIR /var/www/
EXPOSE 80
docker-compose.yml file:
nodejs:
build: .
ports:
- "8001:80"
- "3000:3000"
volumes:
- ~/Web/docker/nodejs/www:/var/www
Commands:
$ docker-compose build nodejs
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nodejs_nodejs latest aece5fb27134 2 minutes ago 596.5 MB
shawnzhu/ruby-nodejs 0.12.7 bbd5b568b88f 5 months ago 547.5 MB
$ docker-compose up -d nodejs
Creating nodejs_nodejs_1
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c24c6d0e756b nodejs_nodejs "/bin/bash" About a minute ago Exited (0) About a minute ago nodejs_nodejs_1
As you can see the docker-compose up -d
should have created a container and run it on the background, but it didn't. Instead it exited with code 0.
If your Dockerfile doesn't do anything (for example a webserver to listen on port 80), it will be discarded as soon as it finishes running the instructions. Because Docker containers should be "ephemeral".
If you just want to start a container and interact with it via terminal, don't use docker-compose up -d
, use the following instead:
docker run -it --entrypoint=/bin/bash [your_image_id]
This will start your container and run /bin/bash
, the -it
helps you keep the terminal session to interact with the container. When you are done doing your works, press Ctrl-D
to exit.
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