Cybrix
Cybrix

Reputation: 3318

How to setup a small website using docker

I have a question regarding Docker. That container's concept being totally new to me and I am sure that I haven't grasped how things work (Containers, Dockerfiles, ...) and how they could work, yet.

Let's say, that I would like to host small websites on the same VM that consist of Apache, PHP-FPM, MySQL and possibly Memcache.

This is what I had in mind:

1) One image that contains Apache, PHP, MySQL and Memcache 2) One or more images that contains my websites files

I must find a way to tell in my first image, in the apache, where are stored the websites folders for the hosted websites. Yet, I don't know if the first container can read files inside another container.

Anyone here did something similar?

Thank you

Upvotes: 2

Views: 1141

Answers (2)

Usman Ismail
Usman Ismail

Reputation: 18649

Your container setup should be:

  1. MySQL Container
  2. Memcached Container
  3. Apache, PHP etc
  4. Data Conatainer (Optional)

Run MySQL and expose its port using the -p command:

docker run -d --name mysql -p 3306:3306 dockerfile/mysql

Run Memcached

docker run -d --name memcached -p 11211:11211 borja/docker-memcached

Run Your web container and mount the web files from the host file system into the container. They will be available at /container_fs/web_files/ inside the container. Link to the other containers to be able to communicate with them over tcp.

docker run -d --name web -p 80:80                  \ 
    -v /host_fs/web_files:/container_fs/web_files/ \ 
    --link mysql:mysql                             \
    --link memcached:memcached                     \
    your/docker-web-container

Inside your web container look for the environment variables MYSQL_PORT_3306_TCP_ADDR and MYSQL_PORT_3306_TCP_PORT to tell you where to conect to the mysql instance and similarly MEMCACHED_PORT_11211_TCP_ADDR and MEMCACHED_PORT_11211_TCP_PORT to tell you where to connect to memcacheed.

Upvotes: 4

Adrian Mouat
Adrian Mouat

Reputation: 46480

The idiomatic way of using Docker is to try to keep to one process per container. So, Apache and MySQL etc should be in separate containers.

You can then create a data-container to hold your website files and simply mount the volume in the Webserver container using --volumes-from. For more information see https://docs.docker.com/userguide/dockervolumes/, specifically "Creating and mounting a Data Volume Container".

Upvotes: 1

Related Questions