
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
This is a Docker image that aims to have up-to-date C++ libraries and tools for use. Regard for backwards-compatibility is not ***ed.
Libraries
Tools
Compilers
Linkers
Runtime analysis
Build tools
default (GCC) and clang (uses libc++ and libc++abi))Other
To install Docker, please be sure to choose the link to the operating system that best suits your laptop. Please be sure to install Docker by following the instructions provided: Docker can often be out-of-date on Linux systems, which exposes security vulnerabilities and can make removing the Docker packages a nightmare.
Note that while I can try to assist, I am not an expert with Docker, and you might be required to post your questions to a forum (please link me if you do so that we both learn).
Hello, world!
This is a first Docker program.
docker run --rm hello-world into the terminal and press Enter. The following
text should appear.What we've done here is instruct to the Docker that we'd like to run the container called
hello-world. The --rm flag tells the Docker daemon to clean up the Docker container once we
finish using it, so that it's not hanging around, consuming resources.
Because we didn't have the Docker image already downloaded, the Docker daemon will attempt to download the image from the DockerHub server.
Mounting a volume
In this section, we'll look at exposing a single directory on your computer to the Docker image so
that you can interact with the real world. We'll also use this section to download and run
amcpp-stdlib for the first time. If you're using Windows, you'll need to do a few extra steps, and
if you're using Windows 10 with Azure Active Directory, you'll need to do a few more steps before
that.
Initial steps for Windows 10 with Azure Active Directory only
If you don't use Windows 10 with Azure Active Directory, you can skip this step. If you're not sure whether you've got an Active Directory setup, skip this section for now, and if you run into problems
Note that if you ever delete docker_user or demote docker_user to a standard user, you'll experience problems.
Initial steps for all Windows 10 users
Steps for all users
amcpp-stdlib.docker run --rm -v <absolute-path-to-amcpp-stdlib>:/data cjdb/amcpp-stdlib /bin/bash -c 'echo "hello" > /data/hello.txt'
You'll see a long list of images being downloaded, and then the prompt should return.
cat amcpp-stdlib/hello.txt. The word hello should appear on the line above your prompt.
What we've done here is downloaded and run the container cjdb/amcpp-stdlib, which is the container
used in Applied Modern C++. The -v <absolute-path-to-amcpp-stdlib>:/data tells Docker to mount
(expose) the directory amcpp-stdlib under the directory /data in the Docker image.
When normally we write something to disk in a Docker container, it's not actually written to disk,
and will disappear when we exit the Docker environment. Anything written to this /data directory
will be written to your physical disk, and persist until you delete it.
Finally, /bin/bash -c 'echo "hello" > /data/hello.txt' is the command we provide to the Docker
container to do work. In this case, we start a shell and write to a file called hello.txt in the
special /data directory (which is really an access point to our amcpp-stdlib directory).
Compiling a program
docker run --rm -i -t -v <absolute-path-to-amcpp-stdlib>:/data cjdb/amcpp-stdlib.root@b87288407b4a:/#. The
-i -t flags have enabled us to enter an interactive mode with pseudo-TTY, so that we can
provide many commands to the Docker container, and interleave them with actions such as reading
output before making the next command, or more regularly interacting with a program.
cd /data && ls && rm hello.txt && ls. You should see hello.txt appear
exactly once.
cppcat > hello.cpp #include <iostream> int main() { std::cout << "Hello, world!\n"; }
c++ -Wall -Wextra -Werror -std=c++17 -o hello hello.cpp../hello. The message Hello, world! should appear on its own line.clang++ -Wall -Wextra -Werror -std=c++17 -o hello2 hello.cpp../hello2. The message Hello, world! should appear on its own line again.
exit to return you to your original terminal.Debugging a program
Docker has certain security mechanisms in place, which make it impossible to run a debugger over a program. In this section, we'll look at how to enable debugging, profiling, and other forms of run-time analysis.
docker run --rm --cap-add=SYS_PTRACE -i -t -v <absolute-path-to-amcpp-stdlib>:/data cjdb/amcpp-stdlib.
This lets us add the Linux capability of using ptrace, which is used on Linux systems
for runtime analysis. Once again, we're in an interactive pseudo-TTY session.cd /data.g++ -Wall -Wextra -Werror -g -o hello hello.cpp.gdb -q hello.r and press Enter to run the program hello.Hello, world! should appear on its own line.q and press Enter to exit GDB.valgrind ./hello. The following should appear.
Using this container on Windows
Docker creates a virtual machine that talks with Windows via the SMB protocol. By default, SMBv3 is
used, but unfortunately, there's a bug in the Windows 10 SMBv3 driver that makes it impossible to
enact certain developer tools, such as parallel builds and link-time optimisation. This is because
when one process is reading a file, it suddenly disappears from the perspective of the entire
container. Fortunately, there's a workaround, and that's to get Docker and Windows to communicate
via SMBv2. What we'll need to do is create a shared network drive, and share the amcpp-stdlib
directory with said network drive.
To enact this workaround, open PowerShell (this is PowerShell-specific), and enter the following commands. There are a few variables that you'll need to set, so don't just copy and paste!
Note: this workaround unfortunately requires that Docker take the password of an administrator and store it as plaintext. This is not ideal. While care has been taken to ensure that your password is not visible in the terminal, no guarantees are made regarding how Docker will handle this data. Follow with caution.
powershell$username = # the user who shared access to the drive in Docker settings $path = # path to exposed directory $volume = # name you want your volume to have # Share a path across a network. $volume_name = "amcpp-$volume" # do this to make sure it's more likely to be unique New-SmbShare -Name "$volume_name" ` -Path "$path" ` -FullAccess "$username" # Get your password (secure) $secure_password = Read-Host "Enter a password for user account" -AsSecureString # Convert your password to plaintext $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure_password) $password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) $BSTR = $null $secure_password = $null # Apply the permission changes to Docker. docker volume create ` --driver local ` --opt type=cifs ` --opt device="\\$env:computername\$volume_name" ` --opt o="rw,relatime,vers=2.0,sec=ntlmsspi,cache=strict,username=$username,pass=$password,domain=$env:computername,uid=0,noforceuid,gid=0,noforcegid,addr=10.0.75.1,file_mode=0777,dir_mode=0777,iocharset=utf8,nounix,serverino,mapposix,nobrl,mfsymlinks,noperm,rsize=65536,wsize=65536,echo_interval=60,actimeo=1" ` "$volume_name" # Delete the plaintext password $password = $null
From here-on, provided that $username's password doesn't change, you'll be able to use Docker as
though it were a bare-metal machine running Ubuntu 18.04. You should also be able to switch to WSL,
if that is your preferred terminal. Now, when you run Docker, you'll need to run it like so:
docker run --rm --cap-add=SYS_PTRACE -i -t -v $volumne_name:/data cjdb/amcpp-stdlib. The
difference between this and the previous command is that we've replaced the absolute path to the
directory with the name of the volume we're sharing.
If you'd like to undo the above, you can run this:
powershell# Un-apply the permission changes to Docker. docker volume remove "$volume_name" # Close the network share Remove-SmbShare -Name "$volume_name" -Force
Packaging this into a script will reduce the amount of time that you expose your password in plaintext, *** wrapping both segments into a PowerShell script, and running Docker in-between. If you choose to do this, you'll need to use PowerShell at all times.
Acknowledgements
I'd like to thank Morris Hafner for helping debug issues surrounding Conan.io and David Wood for helping me to evaluate the effectiveness of this Docker image. Duncan McBain also provided valuable feedback.
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务