Augustin Riedinger
Augustin Riedinger

Reputation: 22238

Linode/lamp + docker-compose

I want to install linode/lamp container to work on some wordpress project locally without messing up my machine with all the lamp dependencies.

I followed this tutorial which worked great (it's actually super simple).

Now I'd like to use docker-compose because I find it more convenient to simply having to type docker-compose up and being good to go.

Here what I have done:

Dockerfile:

FROM linode/lamp
RUN service apache2 start
RUN service mysql start

docker-compose.yml:

web:
  build: .
  ports:
    - "80:80"
  volumes:
    - .:/var/www/example.com/public_html/

When I do docker-compose up, I get:

▶ docker-compose up
Recreating gitewordpress_web_1...
Attaching to gitewordpress_web_1
gitewordpress_web_1 exited with code 0
Gracefully stopping... (press Ctrl+C again to force)

I'm guessing I need a command argument in my docker-compose.yml but I have no idea what I should set.

Any idea what I am doing wrong?

Upvotes: 0

Views: 2664

Answers (2)

Bimal
Bimal

Reputation: 911

I would like to point you to another resource where LAMP server is already configured for you and you might find it handy for your local development environment.

You can find it mentioned below:

https://github.com/sprintcube/docker-compose-lamp

Upvotes: 0

Armin Braun
Armin Braun

Reputation: 3683

You cannot start those two processes in the Dockerfile. The Dockerfile determines what commands are to be run when building the image.

In fact many base images like the Debian ones are specifically designed to not allow starting any services during build.

What you can do is create a file called run.sh in the same folder that contains your Dockerfile. Put this inside:

#!/usr/bin/env bash

service apache2 start
service mysql start

tail -f /dev/null

This script just starts both services and forces the console to stay open. You need to put it inside of your container though, this you do via two lines in the Dockerfile. Overall I'd use this Dockerfile then:

FROM linode/lamp
COPY run.sh /run.sh
RUN chmod +x /run.sh
CMD ["/bin/bash", "-lc", "/run.sh"]

This ensures that the file is properly ran when firing up the container so that it stays running and also that those services actually get started.

What you should also look out for is that your port 80 is actually available on your host machine. If you have anything bound to it already this composer file will not work. Should this be the case for you ( or you're not sure ) try changing the port line to like 81:80 or so and try again.

Upvotes: 1

Related Questions