python - Is there a way to stop a command in a docker container -


i have docker container running command. in dockerfile last line cmd ["python", "myprogram.py"] . runs flask server.

there scenarios when update myprogram.py , need kill command, transfer updated myprogram.py file container, , execute python myprogram.py again. imagine common scenario.

however, haven't found way this. since command in dockerfile...i can't seem kill it. containers terminal when run ps -aux can see python myprogram.py assigned pid of 1. when try kill kill -9 1 doesn't seem work.

is there workaround accomplish this? goal able change myprogram.py on host machine, transfer updated myprogram.py container, , execute python myprogram.py again.

you use volumes mount myprogram.py source code on container, , docker stop , docker restart container.

to make volume :

add volume directive in dockerfile , rebuild image :

volume /path/to/mountpoint 

and use -v option when running image.

docker run -d -v /path/to/dir/to/mount:/path/to/mountpoint myimage 

/!\ these steps above enough linux environment. /!\

to use else (like docker-machine on osx), must make mount point in vm running docker (probably virtualbox).

you'll have following scheme :

<dir share host (osx)> <= (1) mounted on => <mountpoint on vm> <= (2) mounted on => <container mountpoint>

the (2) linux case (in fact, linux case).

the step added mounting directory want share host on vm.

here steps mount directory want share on mountpoint in vm, , using container :

1- first stop docker machine.

docker-machine stop <machine_name> 

2- add sharedfolder vm.

vboxmanage sharedfolder add <machine_name> --name <mountpoint_name> --hostpath <dir_to_share> 

3- restart docker machine :

docker-machine start <machine_name> 

4- creating mountpoint ssh , mounting sharedfolder on :

docker-machine ssh <machine_name> "sudo mkdir <mountpoint_in_vm>; sudo mount -t vboxsf <mountpoint_name> <mountpoint_in_vm>" 

5- , mount directory on container, run :

docker run -d -v <mountpoint_in_vm>:</path/to/mountpoint (in container)> myimage 

and clean when don't need anymore :

6- unmount in vm :

docker-machine ssh <machine_name> "sudo umount <mountpoint_in_vm>; sudo rmdir <mountpoint_in_vm>" 

7- stop vm :

docker-machine stop <machine_name> 

8- remove shared folder :

vboxmanage sharedfolder remove <machine_name> --name <mountpoint_name> 

here a script made studies purpose, feel free use if can you.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -