Skip to content

Commit 54a310e

Browse files
committed
docs(notes): update Docker image documentation for 2025-03-21
1 parent 245d5dd commit 54a310e

File tree

1 file changed

+166
-1
lines changed

1 file changed

+166
-1
lines changed

notes/2025-03-21-docker-image-en.md

+166-1
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,169 @@ Test the app from the server or externally:
171171
- **Docker Compose**: For multi-container setups, use a `docker-compose.yml` file.
172172
- **Restart Policy**: Add `--restart unless-stopped` to ensure the container restarts on server reboot.
173173

174-
Let me know if you need help with any specific part!
174+
Let me know if you need help with any specific part!
175+
176+
---
177+
178+
From the error output you provided, there are a few issues preventing your `docker build` command from succeeding. Let’s break them down and resolve them step-by-step.
179+
180+
---
181+
182+
### Issues Identified
183+
1. **Missing `docker-buildx` Plugin**
184+
Error: `fork/exec /Users/lzwjava/.docker/cli-plugins/docker-buildx: no such file or directory`
185+
This suggests that Docker is trying to use the `buildx` plugin (a modern build tool), but it’s not installed or configured correctly.
186+
187+
2. **Legacy Builder Deprecation Warning**
188+
Warning: `DEPRECATED: The legacy builder is deprecated...`
189+
Docker recommends switching to BuildKit (`buildx`), but it’s falling back to the legacy builder, which is failing.
190+
191+
3. **Docker Daemon Not Running**
192+
Error: `Cannot connect to the Docker daemon at unix:///Users/lzwjava/.docker/run/docker.sock. Is the docker daemon running?`
193+
The Docker daemon (the background service that manages containers) isn’t running on your system.
194+
195+
4. **File Access Errors**
196+
Errors: `Can't add file ... to tar: io: read/write on closed pipe` and `Can't close tar writer...`
197+
These are secondary issues caused by the build process failing due to the daemon not running.
198+
199+
5. **Proxy Settings Detected**
200+
Your system is using proxies (`HTTP_PROXY` and `HTTPS_PROXY`). This might interfere with Docker if not configured properly.
201+
202+
---
203+
204+
### Step-by-Step Fix
205+
206+
#### 1. Verify Docker Daemon is Running
207+
The core issue is that the Docker daemon isn’t running. Here’s how to fix it:
208+
209+
- **On macOS** (assuming you’re using Docker Desktop):
210+
1. Open Docker Desktop from your Applications folder or Spotlight.
211+
2. Ensure it’s running (you’ll see the Docker whale icon in the menu bar turn green).
212+
3. If it’s not starting:
213+
- Quit Docker Desktop and restart it.
214+
- Check for updates: Docker Desktop > Check for Updates.
215+
- If it still fails, reinstall Docker Desktop from [docker.com](https://www.docker.com/products/docker-desktop/).
216+
217+
- **Check via Terminal**:
218+
Run:
219+
```bash
220+
docker info
221+
```
222+
If the daemon is running, you’ll see system info. If not, you’ll get the same "Cannot connect" error.
223+
224+
- **Restart Daemon Manually** (if needed):
225+
```bash
226+
sudo launchctl stop com.docker.docker
227+
sudo launchctl start com.docker.docker
228+
```
229+
230+
Once the daemon is running, proceed to the next steps.
231+
232+
---
233+
234+
#### 2. Install `buildx` Plugin (Optional but Recommended)
235+
Since the legacy builder is deprecated, let’s set up `buildx`:
236+
237+
1. **Install `buildx`**:
238+
- Download the binary manually or use Docker’s instructions:
239+
```bash
240+
mkdir -p ~/.docker/cli-plugins
241+
curl -SL https://github.com/docker/buildx/releases/download/v0.13.0/buildx-v0.13.0.darwin-amd64 -o ~/.docker/cli-plugins/docker-buildx
242+
chmod +x ~/.docker/cli-plugins/docker-buildx
243+
```
244+
(Check the [latest release](https://github.com/docker/buildx/releases) for your OS/architecture, e.g., `darwin-arm64` for M1/M2 Macs.)
245+
246+
2. **Verify Installation**:
247+
```bash
248+
docker buildx version
249+
```
250+
251+
3. **Set BuildKit as Default** (optional):
252+
Add this to `~/.docker/config.json`:
253+
```json
254+
{
255+
"features": { "buildkit": true }
256+
}
257+
```
258+
259+
Alternatively, you can skip this and use the legacy builder for now (see Step 4).
260+
261+
---
262+
263+
#### 3. Handle Proxy Settings
264+
Your proxy settings (`http://127.0.0.1:7890`) might interfere with Docker’s ability to fetch images. Configure Docker to use them:
265+
266+
1. **Via Docker Desktop**:
267+
- Open Docker Desktop > Settings > Resources > Proxies.
268+
- Enable "Manual proxy configuration" and enter:
269+
- HTTP Proxy: `http://127.0.0.1:7890`
270+
- HTTPS Proxy: `http://127.0.0.1:7890`
271+
- Apply & Restart.
272+
273+
2. **Via CLI** (if not using Desktop):
274+
Create or edit `~/.docker/config.json`:
275+
```json
276+
{
277+
"proxies": {
278+
"default": {
279+
"httpProxy": "http://127.0.0.1:7890",
280+
"httpsProxy": "http://127.0.0.1:7890"
281+
}
282+
}
283+
}
284+
```
285+
Restart Docker after editing.
286+
287+
---
288+
289+
#### 4. Retry the Build
290+
Now that the daemon is running and proxies are configured, try building again:
291+
292+
```bash
293+
docker build -t myapp:latest .
294+
```
295+
296+
- If you installed `buildx`, it will use BuildKit by default.
297+
- If you skipped `buildx`, add `--progress=plain` to force the legacy builder:
298+
```bash
299+
docker build --progress=plain -t myapp:latest .
300+
```
301+
302+
---
303+
304+
#### 5. Troubleshoot `.git/hooks` Error (If Persists)
305+
The `.git/hooks/pre-rebase.sample` error suggests Docker is trying to include unnecessary files in the build context. Exclude them with a `.dockerignore` file:
306+
307+
1. Create `.dockerignore` in the same directory as your `Dockerfile`:
308+
```
309+
.git
310+
.gitignore
311+
*.md
312+
target/*
313+
!target/*.jar
314+
```
315+
2. This tells Docker to ignore the `.git` folder and everything in `target/` except your JAR file.
316+
317+
3. Retry the build:
318+
```bash
319+
docker build -t myapp:latest .
320+
```
321+
322+
---
323+
324+
### Final Verification
325+
- Check the image:
326+
```bash
327+
docker images
328+
```
329+
- Run it locally:
330+
```bash
331+
docker run -p 8080:8080 myapp:latest
332+
```
333+
- Test with `curl http://localhost:8080`.
334+
335+
---
336+
337+
### Next Steps
338+
Once the image builds successfully, follow the deployment steps from my previous response (e.g., push to a registry or transfer to a server). Let me know if you hit any more issues!
339+

0 commit comments

Comments
 (0)