You may need to get back to docker's basic concepts a little more in depth. Not sure where you learned from, but I would recommend "That devops guy" on youtube: https://www.youtube.com/watch?v=wyjNpxLRmLg&list=PLHq1uqvAteVvqQaaIAvfIWWTL_JmmXcfg
More in the PHP ecosystem, have a look at https://serversforhackers.com/t/containers
In your case, you need first to understand docker, then docker-compose.
On the docker side, you have a concept of "image", which describes how to create a "container". Think of the image as a sort of recipe, and when you docker run this image, you get a meal (a container).
In your case, you want to add pecl's http request library to phpstorm/php-71-apache-xdebug-26
, therefore you need to execute some more instructions on top of the existing image. This is where the Dockerfile
, docker build
and FROM
are in play.
FROM phpstorm/php-71-apache-xdebug-26
# ...
Once this is done, the build is done, you may run a container that has all the capabilities of the base image (from) + your customisations.
Time to get docker-compose
on board. Docker compose is doing the orchestration part for you, meaning it will only execute many docker commands in the right sequence do avoid having to type all of the commands yourself.
version: "3.8"
services:
my-first-service:
image: phpstorm/php-71-apache-xdebug-26
my-second-service:
build:
context: .
dockerfile: Dockerfile
In the docker-compose.yml
above, I am describing two services.
What docker-compose will do when doing up
is the following:
- create a network *_default (docker network create)
- docker pull the image of my-first-service
- run a container *_my-first-service_1 (docker run)
- do a
docker build -t *_my-second-service -f Dockerfile .
(based on dockerfile and context)
- do a
docker run
of the image created.
In your case, you want to be in the same disposition as the second service, building the image first, and then running the container.
Because you created your container with an image, you only have the specifics of said image, and never called your own dockerfile.