Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

420
Views
Configure un contenedor Docker con solo el comando docker-compose up

Tengo una evaluación en la que tengo que crear un contenedor Docker con CakePHP. Ya tengo un contenedor Docker en funcionamiento con CakePHP y ejecuto los siguientes comandos para mi contenedor:

 docker-compose build docker-compose run cakephp composer install --no-interaction docker-compose run cakephp bin/cake migrations migrate docker-compose run cakephp bin/cake migrations seed docker-compose up

El objetivo es reducir el proceso a solo ejecutar el comando único docker-compose up para poder comenzar a probar el contenedor. Soy muy nuevo en Docker y CakePHP, así que no estoy seguro de cómo hacer esto.

¡Cualquier ayuda es muy apreciada!

Dockerfile

 #start with our base image (the foundation) - version 7.1.29 FROM php:7.1.29-apache #install all the system dependencies and enable PHP modules RUN apt-get update && apt-get install -y \ gcc \ make \ autoconf \ libc-dev \ pkg-config \ libicu-dev \ libpq-dev \ libmcrypt-dev \ mysql-client \ git \ zip \ unzip \ && rm -r /var/lib/apt/lists/* \ && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \ && docker-php-ext-install \ intl \ mbstring \ mcrypt \ pcntl \ pdo_mysql \ pdo_pgsql \ pgsql \ opcache RUN set -eux; apt-get update; apt-get install -y libzip-dev zlib1g-dev; docker-php-ext-install zip #install composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer ENV COMPOSER_ALLOW_SUPERUSER=1 #set our application folder as an environment variable ENV APP_HOME /var/www/html #change uid and gid of apache to docker user uid/gid RUN usermod -u 1000 www-data && groupmod -g 1000 www-data #change the web_root to laravel /var/www/html/public folder RUN sed -i -e "s/html/html\/webroot/g" /etc/apache2/sites-enabled/000-default.conf # enable apache module rewrite RUN a2enmod rewrite && \ echo "ServerName localhost" >> /etc/apache2/apache2.conf #copy source files and run composer COPY . $APP_HOME # install all PHP dependencies RUN composer install --no-interaction #change ownership of our applications RUN chown -R www-data:www-data $APP_HOME

docker-compose.yml

 version: '2' services: cakephp: build: . depends_on: - mysql links: - "mysql" ports: - "4000:80" volumes: - .:/var/www/html/ environment: - SECURITY_SALT= *some salt here* - MYSQL_URL=mysql - MYSQL_USERNAME=root - MYSQL_PASSWORD=root mysql: image: mysql:5.6 volumes: - mysql-data:/var/lib/mysql environment: - MYSQL_DATABASE=cakephp - MYSQL_ROOT_PASSWORD=root volumes: mysql-data:
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Opción 1

Lo que suelo hacer para reducir mis comandos cuando manejo Docker y Docker Compose en general es usar un Makefile .

Entonces, en tu caso, podrías escribir algo como:

Makefile

 SUDO := $(shell groups | grep -q docker || echo sudo) .PHONY: start start: $(SUDO) docker-compose build \ && $(SUDO) docker-compose run cakephp composer install --no-interaction \ && $(SUDO) docker-compose run cakephp bin/cake migrations migrate \ && $(SUDO) docker-compose run cakephp bin/cake migrations seed \ && $(SUDO) docker-compose up

Todo lo que tendría que hacer entonces es colocar este archivo en la carpeta de su proyecto y ejecutar make start .

(La parte $(SUDO) garantiza que pueda ejecutar esto cómodamente incluso con un usuario que no está en el grupo de docker ).

opcion 2

Para ejecutar realmente docker-compose up (quizás con el indicador --build ), tendría que escribir un pequeño script que COPY en la imagen de Docker (ya lo está haciendo con COPY . $APP_HOME , siempre que coloque este script en el lugar al que apunta el contexto de compilación de Docker) y luego utilícelo como ENTRYPOINT .

Algo como esto debería funcionar para usted.

punto de entrada.sh:

 #!/bin/sh set -e cakephp composer install --no-interaction cakephp bin/cake migrations migrate cakephp bin/cake migrations seed exec "$@"

En su Dockerfile, tendría que poner ENTRYPOINT ["/bin/sh", "entrypoint.sh"]

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!