diff --git a/dotfiles/docker.bash b/dotfiles/docker.bash index 0504420dd520f77891edc5e1c078b8a77d0663c9..f0d00ac775ca0741d0f768b92981713c24711865 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(){