R
R
rizzli2015-03-12 16:01:29
Virtualization
rizzli, 2015-03-12 16:01:29

How to use Docker for web development?

Good afternoon.
Until recently, I used Vagrant. But I decided to try working with Docker.
I watched several hours of reports and read several articles. But I did not get a clear understanding of how to properly organize the environment I needed. There are resources in English, but unfortunately I do not speak.
In my work I use:
1. debian, nginx, php-fpm, mariadb, drupal.
2. debian, nginx, nodejs.
Should all tasks be in different containers or in one [debian, nginx, php-fpm] container and [mariadb] in another?
If all tasks are in different containers, then how to put them all together? And what to take for the base image of wasps or scratch (empty image)?
Thanks for answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasiliy Zyablitsev, 2015-03-24
@rizzli

Good afternoon.
All, as you called them, "tasks" should be in different containers.
1. What to take for the base image?
What you use is what you take. Do you use Debian at work? Take Debian ( https://registry.hub.docker.com/_/debian/ )
2. To create your own base image that you will later use for the application, here is an example Dockerfile for you:

#
# MyBaseimage Dockerfile
#

# Pull base image.
FROM ubuntu:14.04

MAINTAINER Your Name <[email protected]>

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install -y language-pack-en
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

RUN locale-gen en_US.UTF-8
RUN dpkg-reconfigure locales

RUN echo "Etc/UTC" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

RUN apt-get install -y build-essential
RUN apt-get install -y python python-dev python-setuptools python-pip python-virtualenv
RUN apt-get install -y libxml2-dev wget
RUN apt-get install -y libpcre3
RUN apt-get install -y libpcre3-dev
RUN apt-get install -y libssl-dev
RUN apt-get install -y libncurses5-dev
RUN apt-get install -y git git-core
RUN apt-get install -y libpq-dev

# install nginx
RUN apt-get install -y software-properties-common python-software-properties
RUN apt-get update

Build the image in the directory where you have the Dockerfile
3. Dockerfile to build your image already with the application
#
# MyApp Dockerfile
#

# Pull base image.
FROM your_docker_account/your_baseimage

MAINTAINER Your Name <[email protected]>

# Set instructions on build.
RUN virtualenv /env
ADD ./ /code

RUN cd /code; /env/bin/python setup.py install
RUN cp /code/config/config.yml.docker_example /etc/code/config.yml

# Expose ports.
EXPOSE 8484
WORKDIR /code
CMD ["/env/bin/python", "app.py"]

4. Build an image with the application
5. Run a container with a database, PostgreSQL as an example
similar for mariadb, look for containers here: https://registry.hub.docker.com/
6. Run a container with your application, example:
docker run -d -p :5000:5000 \
  --name my_app_container \
  --link my_postgresdb_container:postgresdb \
  -e DOCKERDB_ENV_POSTGRESQL_DB=mydb_name \
  -e DOCKERDB_ENV_POSTGRESQL_USER=mydb_user \
  -e DOCKERDB_ENV_POSTGRESQL_PASS=super_secret_password \
  your_docker_account/your_app_container

7. Connect to the running container with the application
8. Read the stdout of the running application in the container
+ To automate the launch of all the necessary containers, take Docker Compose ( https://docs.docker.com/compose/ )
Sample configuration file:
your_app:
  build: .
  links:
    - postgresdb
  ports:
    - "5000:5000"
  environment:
    DOCKERDB_ENV_POSTGRESQL_DB: mydb_name
    DOCKERDB_ENV_POSTGRESQL_USER: mydb_user
    DOCKERDB_ENV_POSTGRESQL_PASS: super_secret_password
postgresdb:
  image: kamui/postgresql
  ports:
    - "5432:5432"
  environment:
    POSTGRESQL_DB: mydb_name
    POSTGRESQL_USER: mydb_user
    POSTGRESQL_PASS: super_secret_password

And now instead of points 5 + 6 where we launched containers, we can start everything with one command
+ you can mount the code into a container and develop directly in the docker container.
Hope it helped you somehow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question