From 47a9527e4b1f01cb059a3dd6667d88276e2af74a Mon Sep 17 00:00:00 2001 From: Andres Montano <andres.montano@tecnalia.com> Date: Thu, 1 Dec 2022 14:31:07 +0100 Subject: [PATCH] Redefine rundock command --- dotfiles/docker.bash | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/dotfiles/docker.bash b/dotfiles/docker.bash index 0504420..f0d00ac 100644 --- a/dotfiles/docker.bash +++ b/dotfiles/docker.bash @@ -7,18 +7,26 @@ alias drmi="docker rmi" alias dsp="docker system prune --all" alias dimp="docker image prune" +# Build docker image +# usage: dockbuild {noetic, melodic} +function dockbuild(){ + cd ~/srcs/development_environment/dockerfiles; + docker build -t devenv:$1 --build-arg ROS_DISTRO=$1 -f devenv.Dockerfile . +} + # Run container with rocker # usage: rundock {noetic, melodic} [{remodel_ws, odin_ws}] [cmd] # To share docker --volume /var/run/docker.sock:/var/run/docker.sock:ro function rundock() { - cd ~/ros/$1/$2; - rocker --home --ssh --git --user --nvidia --x11 --network host --name $1 devenv:$1 $3 -} - -# Execute container, move to workspace, and source SHELL -# usage: dat {noetic, melodic} {remodel_ws, odin_ws} -function dat() { - docker exec -it $1 bash -c "cd ~/ros/$1/$2 && $ext" + # Check if the container exist + if [[ $(docker ps -aq -f name=$1) ]]; then + # Attach to conayiner + docker exec -it $1 bash -c "cd ~/ros/$1/$2 && $ext" + else + # Launch container + cd ~/ros/$1/$2; + rocker --home --ssh --git --user --privileged --nvidia --x11 --network host --name $1 devenv:$1 $3 + fi } # Remove all stoped containers @@ -26,22 +34,16 @@ function drma() { drm $(docker ps -a -f status=exited -q) } -# Stop and remove -function dsr() { - docker stop $1; - docker rm $1 -} # Remove all unused or dangling immages function drmui(){ drmi $(dim --filter "dangling=true" -q --no-trunc) } -# Build docker image -# usage: dockbuild {noetic, melodic} -function dockbuild(){ - cd ~/srcs/development_environment/dockerfiles; - docker build -t devenv:$1 --build-arg ROS_DISTRO=$1 -f devenv.Dockerfile . +# Stop and remove +function dsr() { + docker stop $1; + docker rm $1 } # function runpythonsyntax(){ -- GitLab