On the production server, there was a docker-compose.yml, which was accidentally overwritten, the containers are still running from the old docker-compose.yml, is there a way to get the old docker-compose.yml content from the still running containers
I tried restoring the old file in the terminal
Related
I installed Docker and Docker Compose
I downloaded the latest release Docker-based Drupal stack
(there are php, mariadb, apache images etc.) and put it in the my project
folder /var/www/html/mydrupaldocker
Next, I made the settings in the .env and docker-compose.yml files and running the containers with the command:
docker-compose up -d
After running images from this folder, as well as adding the unzip drupal 9 folder to the my project folder, I will start installing drupal 9 in the browser.
And I have questions on two possible situations:
Situation №1:
I made mistakes in the file docker-compose.yml I have the commented code which is responsible for the few images. Accordingly, the containers were not started. And I want to place the project in another place of the computer (not critical, but it is desirable)
I can do:
docker-compose stop
docker-compose rm
Fix everything that I need. And run again:
docker-compose up -d
Is it right to do so? Or do I need something otherwise?
Situation №2:
Everything is set up well, running all the necessary containers, installed the Drupal 9 site in the container. And then I created a sub theme, added content, wrote code in php, js, css files, etc.
How do I commit the changes now? What commands do you need to write in the terminal? For example, in technology such as git, this is done with the commands:
git add.
git commit -m "first"
How is it done in Docker? Perhaps there will be a situation when I need to roll back the container to the version below.
Okay, let's go by each case.
Situation No.1
Whenever you make changes to docker-compose.yml, it's fine to restart the service/images so they reflect the new changes. It could be as minor as a simple port switch from 80 to 8080. Hence, you could just do docker-compose stop && docker-compose up -d and docker-cli will restart the containers with the new changes.
You don't really need to remove the containers/services unless you have used custom Dockerfile and have made changes to it. Although, your below assumption would still give the same result, it's just has an extra step of removing the containers without any changes being done to the actual docker images.
I can do: docker-compose stop docker-compose rm
Fix everything that I need. And run again:
docker-compose up -d
Situation No.2
In this you would be committing your entire project to git along with your Dockerfile and docker-compose.yml file from your host machine and not the container. There's no rocket science here.
You won't be committing your code to git via the containers. The containers are only for deploying and testing your code. You would be committing just the configuration files i.e Dockerfile (if custom is used offcourse) and docker-compose.yml file along with your source code to git. The result would be that, any developer who is collaborating with you in a team, can just take a pull of the project and run docker-compose up -d and the same containers/services running on your machine will be up and running on the host machine of the other dev.
Regarding how to roll back to old version of docker services, you can just rollback to a previous commit and the docker-compose.yml will be reverted. Then you can just do:
docker-compose down && docker-compose up -d
I'm new to docker-compose. Before, when I started containers manually, after a host reboot I had to start the containers manually.
Today I found that -after a host reboot- I had 4 containers running. Those were previously started with docker-compose.
But docker-compose does not work well unless you are in the proper directory with the docker-compose.yml.
Question
How can I know what docker-compose.yml or (which path) was used to launch the docker containers that I find already started as soon as I login after a reboot?
I tried
docker inspect xxxxx
but I could not find any clue on what docker-compose.yml was used to launch.
docker-compose is not starting anything.
The Docker daemon is starting containers on which you have set a restart policy (possibly in one of your docker-compose.yaml files). You can simply remove these containers (docker container rm ...) if you don't need them anymore, or you can reset the restart policy using docker container update --restart=no <image_name_or_id>.
You can read more about restart policies here.
But docker-compose does not work well unless you are in the proper directory with the docker-compose.yml.
Since docker-compose isn't involve at this stage (it may have been responsible for creating the containers but it is not responsible for restarting them), this isn't a problem. Setting an appropriate restart policy on your containers via your docker-compose.yml is the correct way to enable containers to start at boot.
You can set a restart policy when you start a container using docker run by including the appropriate --restart=<policy> option on the command line.
in compose file use restart: always to run after machine is rebooted
services:
service1:
image: serice1:latest
restart: always
I think I have an understanding of this but just would like some clarification.
I have a docker-compose file with all my services in it. Did a docker-compose up and everything is fine. One of my services is a worker that needs to be restarted whenever my files change. For now I do a bind-mount from my host to the container. When I make some changes on my local system and then restart the worker container and it should pick up the changes.
If I do docker-compose restart , then it works and my changes are picked up.
If I do docker restart , then it seems to just cache the old environment, the files my worker runs are the "old" ones even though I can see the file changed when I ssh into the container.
I'm guessing it has something to do with docker-compose reloading configs or something? For now I'm just going continue to use docker-compose restart but I'd like a better understanding of what's going on.
Thanks for any help.
I am new with docker; I have a docker-compose.yml file. My question is: if I run docker-compose up after modifying this file, will this remove the old postgres db?
If the configuration for the PostgreSQL service or one of its dependencies has changed since the last time you ran docker-compose up, Docker Compose will destroy and recreate the container, but the new PostgreSQL container will continue to use the same volumes as the old one. If you're using the official postgres image (rather than an image you made yourself), all of the database's data will be stored in a Docker volume by default, and so the data will be preserved across invocations of docker-compose up (but not invocations of docker-compose rm postgres-service or docker-compose down).
I'm trying to teach myself about Docker and using the docker-compose.yml to play around with images and the compose file. I've got the Wordpress image up and running using successfully docker-compose.yml up -d via the tutorial here... https://docs.docker.com/compose/wordpress/), but as soon as I make changes to the compose file and docker-compose.yml up -d again I can't access the changes again and have to completely delete images/containers/docker machine's to get my changes to work.
What am I doing wrong, what's the process to restart/delete the minimum amount to see my docker-compose.yml changes so I can play around with docker-compose.yml?
docker-compose stop to stop the stack
docker-compose start to start the stack
Both above will not remove your container, but rather shutdown and start them again, without any loses, even on the container filesystem, not only the volumes
docker-compose down will remove the containers of your services and all anonymous volumes assigned to them.
Be aware, not all changes in the docker-compose file can be applied using start/stop, rather most of the time, you have to do a down/up. Things like volumes/ports cannot be hot-applied like this.