I copy the file to the docker from the host (docker cp file.txt 4f20e373e04b: / root) I go to the docker's directory and there is this file. But as soon as I restart the docker, this file is lost. I launch the docker with the command docker run -p 5000: 5000 lorry-server. I am new to dockers, please help)
2 answers
If I understand correctly, then docker run creates a new container from image and there is no longer this file in it. You need to add this file to docker image and then it will be at the start of the container.
|
The data in the container is saved, if you stop, just stop the container and not delete it.
# запуск контейнера (без опции --rm) docker run --name foo ... # скопировали туда файлик docker cp ... # остановили контейнер docker stop foo # запустили контейнер, файлик еще там docker start foo # остановили и удалили контейнер docker stop foo && docker rm foo # файлик утерян навсегда, надо снова делать docker run и docker cp
In general, in order not to make unnecessary gestures, I recommend using the -v
option in the docker run
, then your file will always be in a container
docker run -v /path/to/file.txt:/path/inside/container/file.txt
|