Reputation: 9480
For the sake of simplicity, use ubuntu
image as an example.
Upvotes: 1
Views: 70
Reputation: 347
I often find it easier to use docker-compose, particularly if there's a high chance I'll want to both mount-volumes and link the container to another container at some point in the future.
Create a file in that folder called "docker-compose.yml". In this file, enter:
ubuntucontainer:
image: "ubuntu:latest"
ports:
- "80:80"
volumes:
- ./files:/files
Whenever you need to start the box, navigate to "ubuntu" and type docker-compose up
. To stop again, use docker-compose stop
.
The advantage of using docker compose is that if you ever want to link-up a database container this can be done easily by adding another container to the yaml file, and then in the ubuntucontainer container adding a links
section.
Not to mention, docker-compose up
is quite minimal on the typing.
(Also, forwarding the ports with 80:80
may not be strictly necessary, it depends on what you want the box to do.)
Upvotes: 2
Reputation: 9480
$ cd ~
$ docker run -it -v /$(pwd)/ubuntu:/windows --name ubu ubuntu
$ docker start -i ubu
You will get an empty folder named ubuntu
in your Windows user directory. You will see this folder with the name windows
in your ubuntu container.
cd ~
is for making sure you are in Windows user directory.-it
stands for interactive, so you can interact with the container in the terminal environment. -v host_folder:container_folder
enables sharing a folder between the host and the container. The host folder should be inside the Windows user folder. /$(pwd)
translates to //c/Users/YOUR_USER_DIR
in Windows 10. --name ubu
assigns the name ubu
to the container.-i
stands for interactiveUpvotes: 1