How to start a Docker container with a volume mounted in a batch file

What is this?

This is a method to mount the location of the batch file as volume when starting the docker container. This is useful when you want to use bash wherever you want.

Confirmation environment

Windows 10 (1909) Docker version 19.03.13


Create the following batch file and place it wherever you like. Double-click to start. If you want to pass arguments to the container, D & D to a batch file.


@rem container image
@set IMAGE=buildpack-deps:buster
@rem working directry in container
@set WORK=/workspace
@rem ###########################
@cd /d %~dp0
docker run -it --rm -v "%CD%:%WORK%" -w "%WORK%" %IMAGE% %*
@if errorlevel 1 (
  exit /b %errorlevel%
@exit /b 0

I have set the docker image name to start in IMAGE. Please rewrite it with your favorite image. Specify the mount destination in WORK. Please rewrite to an appropriate mount point without a container.

Recommended Posts

How to start a Docker container with a volume mounted in a batch file
How to run a job with docker login in AWS batch
How to mount the batch file location via WSL2 and start the Docker container
How to start Camunda with Docker
[Docker] How to see the contents of Volumes. Start a container with root privileges.
How to make a jar file with no dependencies in Maven
How to check the logs in the Docker container
How to get a heapdump from a Docker container
How to update pre-built files in docker container
[How to insert a video in haml with Rails]
[Java] How to start a new line with StringBuilder
How to save a file with the specified extension under the directory specified in Java to the list
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
How to request a CSV file as JSON with jMeter
[Docker] Delete only the volume associated with a specific container
Mapping to a class with a value object in How to MyBatis
How to set up a proxy with authentication in Feign
How to make a Java container
How to develop in a container with --privileged and / sbin / init passed in VSCode Remote Containers
[Linux] Start Apache container with Docker
How to rename a model with foreign key constraints in Rails
How to open a script file from Ubuntu with VS code
How to build an environment with Docker, which is the minimum required to start a Rails application
[Xcode] How to add a file
How to share files with Docker Toolbox
How to use named volume in docker-compose.yml
[Rails] How to use rails console with docker
How to insert a video in Rails
How to add jar file in ScalaIDE
How to use Docker in VSCode DevContainer
How to achieve file download with Feign
How to publish a library in jCenter
Understand in 5 minutes !! How to use Docker
Note: [Docker] How to start and stop
How to achieve file upload with Feign
How to build Rails 6 environment with Docker
How to quickly create a reverse proxy that supports HTTPS with Docker
[Personal memo] How to interact with a random number generator in Java
How to develop from VScode in a remote destination environment or a remote destination container environment
[Rails] How to log in with a name by adding a devise name column
Starting with installing Docker on EC2 and running Yellowfin in a container
How to execute with commands of normal development language in Docker development environment
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to migrate a web application created in a local docker environment to AWS
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Two ways to start a thread in Java + @
Read a string in a PDF file with Java
How to deploy a container on AWS Lambda
How to display a web page in Java
How to get the ID of a user authenticated with Firebase in Swift
Setting to exit from Docker container with VScode
How to run a djUnit task in Ant
I made a Docker container to run Maven
How to add a classpath in Spring Boot
How to create a theme in Liferay 7 / DXP
How to store data simultaneously in a model associated with a nested form (Rails 6.0.0)
How to give your image to someone with docker
How to easily create a pull-down in Rails
How to create an Excel form using a template file with Spring MVC
How to bind to property file in Spring Boot
How to use docker compose with NVIDIA Jetson