Docker Community Forums

Share and learn in the Docker community.

New to Docker. Need help building my first container

(Rudyrana) #1

I am fairly new to Docker and am trying to BUILD my first Docker Container. I want to create a container of Apache, MySQL, and PHP that is installed on a my MAC. I was reading online and therein it mentioned that I will need to install Packages and Start the Services for Apache, MySQL, and PHP.

Apache and PHP are already pre-installed on my MAC; I will just need to install MySQL and configure the “htdocs” to my specific requirements.

Do I need to use Dockerfile or Docker-compose for what I need to do? How can I do this and create a Container?

I was searching other write-ups on Internet and in one of them it mentioned “FROM: ubuntu:latest”. What should I use for MAC in the FROM, when writing my first Dockerfile?

(David Maze) #2

Your life will be vastly easier if you set up one container to do one thing. So you want to create three containers, one for each of these services. And of these you can probably use the standard mysql image unmodified for your database, and there’s prepackaged PHP+Apache in a single image, so you only need to create one custom image to add your application to that PHP+Apache image.

Doesn’t matter: Docker images are completely independent of what may or may not be installed on your host. Having the software available on your host will almost definitely make developing easier.


I see a lot of posts here that start with “I docker run an interactive container and installed software into it”, but all of your hard work will be lost as soon as you exit the container. A Dockerfile is a standard place to write down what the steps are to build an image, and it’s just an annotated shell script. When you change your application, after running its tests locally, you can easily docker build a new image. docker exec and interactive containers are super useful for debugging but they shouldn’t be part of your core workflow.

Very useful for starting the two connected containers. Not, strictly speaking, required, but I’d probably start there.

I’d suggest clicking the “Docs” link at the top of this page to get to the official Docker documentation. Especially “Get Started”, “Get started with Docker”, “Part 2: Containers” is an excellent introduction to writing and running custom images.

Unfortunately, none of the official tutorials on the front page really go into Docker Compose on a single-host setup. “Product Manuals”, “Docker Compose”, “Overview of Docker Compose” is probably a good starting point.

All of the variants of Docker for Mac use a Linux virtual machine under the hood. I’d recommend the standard php and mysql images as launching points. (And more specifically, your Dockerfile should probably start with FROM php:7.0-apache.)

(Rudyrana) #3

Hello David,

I would like to thank you for having given me these great tips. I will get started and see how things evolve.
Thanks once again.