We cover some more about working directories, the
run command, and update our
exec command doesn't work with a working directory setting, we can run a command that
cd's into a directory and runs the command we want all in one shot:
docker exec -it app bash -c "cd /var/www/html && php artisan list"
We can update our
docker-compose.yml file to add a
working_dir. This should let us avoid doing the above "hack"!
version: '3' services: app: build: context: ./docker/app dockerfile: Dockerfile image: shippingdocker/app:latest networks: - appnet volumes: - ./application:/var/www/html working_dir: /var/www/html cache: image: redis:alpine networks: - appnet volumes: - cachedata:/data db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: secret MYSQL_DATABASE: homestead MYSQL_USER: homestead MYSQL_PASSWORD: secret networks: - appnet volumes: - dbdata:/var/lib/mysql networks: appnet: driver: bridge volumes: dbdata: driver: local cachedata: driver: local
Then commands like:
docker-compose exec app php artisan list
...should just work!