Files
linux_docker/start_docker.fish
John Colvin 56c61231f3 Upgrade ubuntu to latest LTS (22.10)
This is a big upgrade, from 18.04!
2022-10-04 13:49:25 -05:00

101 lines
2.2 KiB
Fish
Executable File

#!/usr/bin/env fish
function print_help_and_exit
echo "\
Start a docker dev container
Usage: start_docker.fish [OPTIONS]
Options:
-i,--image The image to use
-c,--container The name to give the container
-h,--help Print this help message and exit
"
return $argv
end
argparse 'h/help' 'i/image' 'c/container' -- $argv
if set -q _flag_help
print_help_and_exit 0
return 0
end
set pos 1
# Set 'image_name'
set image_name ""
if set -q _flag_image
if test (count $argv) -ge $pos
set image_name "$argv[$pos]"
set pos (math $pos + 1)
if test "$image_name" = ""
echo "Image (-i,--image) must be non-empty"
print_help_and_exit 1
return 1
end
else
echo "Invalid arguments"
print_help_and_exit 1
return 1
end
else
set image_name "bluetradingsystems/spark-crypto-dev"
end
# Set 'cont_name'
set cont_name ""
if set -q _flag_container
if test (count $argv) -ge $pos
set cont_name "$argv[$pos]"
set pos (math $pos + 1)
if test "$cont_name" = ""
echo "Container (-c,--container) must be non-empty"
print_help_and_exit 1
return 1
end
else
echo "Invalid arguments"
print_help_and_exit 1
return 1
end
end
set home_src $HOME/.spark-dev/mounts/$cont_name
set home_tgt $HOME
set repo_src (git rev-parse --show-superproject-working-tree)
set repo_tgt $HOME/(basename $repo_src)
set working_dir $HOME
# Make sure the $home_src dir exists before executing 'docker run' (otherwise
# Docker will automatically create the directory with root ownership).
mkdir -p $home_src
echo "\
Starting container
image_name : $image_name
cont_name : $cont_name
home_src : $home_src
home_tgt : $home_tgt
repo_src : $repo_src
repo_tgt : $repo_tgt
working dir : $working_dir"
docker run \
--net host \
-h (hostname) \
-e "TZ=America/New_York" \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
--name $cont_name \
-v $home_src:$home_tgt \
-v $repo_src:$repo_tgt \
-u (id -u $USER):(id -g $USER) \
-w $working_dir \
--shm-size=4024m \
-t \
-i \
-d \
-e DISPLAY="$DISPLAY" \
"$image_name" \
fixuid bash