0

I am new to Docker and I have a question for it.

I have a docker container including my ASP.NET Core API project.

I would like to change some files in this project and then update it.

But I don't wanna interfere or stop my project running.

Is it possible?

and if it is, how can i do that?

serhatyt
  • 180
  • 2
  • 14
  • Better practice would be to build a new image, deploy it and shift the traffic over. Depending on how you have deployed it, it can be easier or difficult. Kubernetes for example has abstractions like services for that specific purpose. – The Fool Dec 20 '21 at 09:05

3 Answers3

0

you can use docker exec -it <container name> /bin/bash to get a bash shell in the container. Then you can just run every commands to modify the project. Depending on the image of your container maybe the bin/bash can change to get a terminal.

  • what happens if the container restarts for some reason? – The Fool Dec 20 '21 at 09:06
  • If what you mean : "what happens to my modifications if the conainer restarts" by what happens then it depends. If you have modified folders that you mounted by volumes. youe changes can be saved. But if not your changes will be lost. Because if it restarts for some reason unknown you would'not be able to commit the container to image (the second option to still have your changes after container restarts). – Ezekiela Rakotoarijaona Dec 20 '21 at 09:16
0

Containers are ephemeral by definition, I suggest you to modify your project and build it and start a new container and when it is running stop the old one. I think you can also get into the constainer using:

docker exec -it {id_container} bash

then you can use the bash to modify the files that you want to modify, to get the container id you can type:

docker ps

and you can find it under the CONTAINER ID section

badr
  • 94
  • 1
  • 5
0

I see two ways for you to do that. One is to get inside the container and the other one is to create a volume (and mount it), which will allow you to locally make a change and that same change will reflect in the container immediately.

This link might also help - it's about storage in Docker.

These commands do not always work exactly this way, it always depends on your containers, but here you have some examples:

  1. To get inside the container

docker exec -it container ID or container name bash

You can know your container ID and container name by doing docker ps

  1. To create a container with a volume

docker run -d --name my_container -v /project_core_api:/core_api my_image:tag

The left side /project_core_api is in your machine and the right side core_api will be the folder inside the container that will reflect all your changes in /project_core_api.

Pedro Rodrigues
  • 637
  • 6
  • 16