If you do it repeatedly, it’s a better idea to add the required package to the Dockerfile: FROM openjdk:11 RUN RUN WORKDIR "/app" Installing a package in a running container is something that should be done incidentally. Edit text file in terminal debian install#Run the container first (this time mounting a volume is not necessary): docker run -rm -it -name=lol lol bashĪnd then install the editor: apt-get update apt-get -y install vim If using a volume is not an option you can install the editor you need to use in a running container. If you try to list files once again in the container being run you’ll see that newly-created Lol.java file is there: ls Lol.java cat Lol.java public class Lol you can see cat command works, so you can at least view the file’s content. Navigate to the $PWD/app-vol directory from an another terminal and create a Lol.java file. Now if you try to list all the files in the /app directory you will get an empty result: ~/ docker run -rm -it -name=lol -v $PWD/app-vol:/app lol bash ls $PWD/app-vol folder will be created automatically if it does not exist. Īnd finally run the container with a volume attached (a volume can be also created with a docker volume create command): docker run -rm -it -name=lol -v $PWD/app-vol:/app lol bash Now, build an image with: docker build -t lol. Let’s use the following Dockerfile: FROM openjdk:11 WORKDIR "/app" So if you prepared a Dockerfile, built an image and after running a container you need to edit a file you may get surprised: ~/ docker run -it openjdk:11 bash vi Lol.java bash: vi: command not found What are the possible solutions? #1 Use volume From this point of view, having any editor installed is pointless and introduces needless complication. Docker is meant to be lightweight (doing one job and doing it well), hence docker containers are trimmed to a bare minimum - they have only necessary packages installed to play the required role in a given project ecosystem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |