docker In our impression, what is completed is the deployment and collaboration sharing function in the development stage , lately Docker Launched a program suitable for the development stage Docker Environmental container development .
1.1 Development environment preview
The development environment allows you to share ongoing code with team members , So you can collaborate easily . Use Dev Environments when , You can easily set up a repeatable development environment , Versioning environment details with code . You can also share your ongoing code with your team members with one click , Without having to deal with any merge conflicts , At the same time Git Move between branches to put your code on their machines .
The development environment also allows you to switch between the developer environment or the environment of team members , Move between branches to see changes in progress , Without leaving the current Git Branch .
To visit Dev Environments, Please from Docker From the menu Dashboard > Dev Environments.
1.1.1 Start single container development
Click create new environment . This will open “ Create a development environment ” Dialog box .https://github.com/dockersamples/single-dev-env.git Copy it and add it to Remote Git Repository On the tab Repository URL Field .
Now? , Click create .
This will clone the Git Code , Determine the best image for your development environment , Last , Open... In the development environment container VS Code.
In the example above , name wizardly_ellis and relaxed_maclaren It's randomly generated . When creating a development environment , You'll probably see different names .
Hover over the container and click VS Code Open in to start as usual in VS Code Work in China . You can also VS Code Open a terminal in , And then use Git Push or pull code to your repository , Or switch between branches and work as usual .
You can make run stay VS Code Run the command in the terminal to start the application . This will be on the port 8080 Open one on http The server . Open it in a browser http://localhost:8080 To see the running application .
1.1.2 Create a development environment from a specific branch or tag
You can do this by adding @mybranch or @tag As a suffix to your Git URL , From a particular branch （ for example , The branch corresponding to the pull request ） Or tag to create a development environment ：
then Docker Clone the repository with the branch or label you specify .
- First , We use Git The credentials cloned one in the container Git The repository . Please note that , This does not conflict with any local files on your host .
- What we need for the example project Go The tool is automatically set for us . Besides , This will not cause any friction with our local tool settings .
- Last , We can use VS Code The terminal runs the application server in the container , And automatically access it from the host .
2.1 Share your development environment
When you're ready to share your environment , Just click the share button and specify the to push the development environment to Docker Hub Namespace .
This will create the... Of the development environment Docker image , Upload it to the... You specified in the previous step Docker Hub Namespace , And provide a small tool that can be used to share your work with team members URL.
Your team members need to open “ establish ” Dialog box , choice “ Existing development environment ” tab , Then paste URL. Your development environment is now in exactly the same state as it was when you shared it .
Use this shared development environment , Your team members can access the code 、 Any dependencies and the current Git Branch . They can also review your changes and provide feedback before you create a pull request ！
3.1 Advantages and disadvantages
- this docker dev environment The introduction of the function solves the problems caused by different development environments in the collaborative stage .
- The disadvantage is that DEV If the container is damaged, it will cause irreversible damage to the whole project development .
- Another point is the current way of container collaborative development Docker Only with VScode Completed docking , I hope to develop and IDEA Docking .