How to edit my JS files inside Docker container using Sublime 3?

Asked

Viewed 2,468 times

2

I am using Docker 1.7 on MAC OSX and have created a container with an Apache and a WEB application.

I would like to edit JS fonts using Sublime Text 3.

How can I do that ?

2 answers

3


You can use the functionality VOLUME for that reason.

Suppose your Dockerfile directory is on ~/Desktop/meu-site and that the Document Root of the Apache (Container) site is on /var/www/html

Do the following:

mkdir src
# copie o código de seu site para este diretório src
docker run -d -v ~/Desktop/meu-site/src:/var/www/html

Now do :

subl -a src

Change any file via Sublime Text and reload the WEB page.

Ready ! You will see your change

  • the specification of the volume in the form ~/Desktop/meu-site/src works due to the fact that the MAC OSX or Linux shell solves the ~ for /Users/usuário-logado or /home/usuário-logado depending on the operating system. I opted to use the ~ for the instruction to be portable.

0

Volume mapping is the most appropriate way to do this.

First check which location your container uses to read the codes you want to manipulate. Let’s imagine that it is /var/www/.

If your code is in the folder /home/usuario/codigo, the Docker command for mapping is as follows:

# docker -d -v /home/usuario/codigo:/var/www nome_da_imagem

With this, everything you add and/or modify in the folder /home/usuario/codigo from the Docker host, will be automatically modified in the folder /var/www inside the container.

Note, some specific services need the service to restart in case of a change in code, in which case, just drop the container and start again.

For more information on volume mapping: https://docs.docker.com/reference/commandline/run/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.