Keep container alive and tied with dockers

I want to use docker-compose to build together php and several databases (orientdb, neo4j, etc.). Then go into the php container and use the command to execute the commands.

Individually, all of my containers run smoothly, and when I put them together, they all run. However, I can’t understand for life how to save the php container so that I can enter it for testing.

For simplicity, I just use one database: orient-db.

My docker-compose.yml file:

 version: '2' services: php: build: . links: - orientdb orientdb: image: orientdb:latest environment: ORIENTDB_ROOT_PASSWORD: rootpwd ports: - "2424:2424" - "2480:2480" 

My "php" Dockerfile :

 FROM php:5.6-cli ADD . /spider WORKDIR /spider RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer RUN composer install --prefer-source --no-interaction RUN yes | pecl install xdebug \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini 

I tried (by the way):

  • docker-compose up in one terminal and then docker attach in another
  • including tty and stdin_open in my layout file
  • using the command /bin/bash
  • options CMD exec vendor/bin/phpunit -D FOREGROUND

And some links that I tried: - How to save the Docker container after starting the services? - https://github.com/docker/compose/issues/1926 - https://github.com/docker/compose/issues/423

Any help would be really appreciated.

Thanks.

+8
php docker docker-compose provisioning orientdb
source share
3 answers

Thus, docker-compose is just a backup for the docker engine client. It supports parity function with customer. To diagnose such problems, you should refuse to use the docker layout until you get it working with the regular ole client. Based on your comments here and on another answer, it just sounds like you are not using a container with the daemon process in the foreground. If you want to launch the interactive shell in Docker, you must use the -it flags ( -t selects tty and -i initiates an interactive session). If you do not start Docker with these switches, your container will not be able to survive when you launch an interactive shell, for example. php -a .

This helps to think of Docker as a fantastic way to start a process, not a virtual machine. This is not some kind of “environment” that exists outside the life of any process (and its children) in which you work. Typically, PHP is called by some server (e.g. Apache, Nginx, etc.). What you mean here is that you need the PHP process to run “constantly” so you can peek into the container and check out some things. With the exception of an interactive shell, which will not be possible, and you need to specifically use the -it switch to support the interactive shell process in your container. The real answer here is that you cannot do what you are trying to do here (hold the container for PHP) without any associated daemon process or server listening in the foreground. The reason for this is that this is not how PHP works. If you really want to get into the container from your PHP image, just go into the shell on it:

 docker run -it apollo/php /bin/bash 

... And you will start the container with your PHP image and get a shell on the container (which will die as soon as you exit the shell). But then again, just to repeat from my first paragraph, docker assembly is not the way to go.

+10
source share

If you start with docker-compose up , and there are no errors printed on the terminal, this means that the service stops because it is terminated (unlike any error).

One of the potential reasons for the error is that you send the material to PHP (installing the composer), which will kill the interactive php terminal, which is launched using the php:5.6-cli . To start the php interactive shell, add the following to the end of the Docker file:

CMD ["php", "-a"]

and try again with docker-compose up

Sidenote: when everything works correctly, you can run docker-compose up -d to start in daemon mode to control your terminal again (all stdout + stderr will be logged in the docker container of the corresponding log files).

You can then attach the container to your item. I always found that docker exec -it <containerID> bash was faster than docker attach <container id>

Hope this helps.

+5
source share

If you have a problem launching the zsh shell on a docker container that works with compose, it will close with exit code 0 immediately after starting.

The @Spock comment below the last answer is actually the key, at least for what I need.

Give the command to create dockers for the image:

 command: tail -f /dev/null 

This preserves performance, but also allows it to be gracefully completed.

0
source share

All Articles