Skip to content

Fix running locally with Docker #2797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ COPY Gemfile ./
# Install bundler and dependencies
RUN gem install bundler:2.3.26 && bundle install

# Expose port 4000 for Jekyll server
EXPOSE 4000

# Command to serve the Jekyll site
CMD ["bundle", "exec", "jekyll", "serve", "--host", "0.0.0.0", "--watch"]
CMD ["jekyll", "serve", "-H", "0.0.0.0", "-w", "--config", "_config.yml,_config_docker.yml"]

51 changes: 3 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,58 +41,13 @@ If you are running on Linux it may be necessary to install some additional depen

Working from a different OS, or just want to avoid installing dependencies? You can use the provided `Dockerfile` to build a container that will run the site for you if you have [Docker](https://www.docker.com/) installed.

Start by build the container:
You can build and execute the container by running the following command in the repository:

```bash
docker build -t jekyll-site .
docker compose up
```

Next, run the container:
```bash
docker run -p 4000:4000 --rm -v $(pwd):/usr/src/app jekyll-site
```

To run the `docker run` command on Windows, you need to adjust the syntax for the volume mapping (`-v`) as Windows uses different path formats. Here's how to run your command on Windows:

### Steps for Windows:
1. **Check Docker Installation**: Ensure Docker is installed and running.
2. **Adjust Path for Volume Mapping**:

- On Windows, replace `$(pwd)` with the full absolute path to your current directory. For example:

```bash
-v C:\path\to\your\site:/usr/src/app
```

### Full Command Example:
```bash
docker run -p 4000:4000 --rm -v C:\path\to\your\site:/usr/src/app jekyll-site
```

### Things to Keep in Mind:
1. **Use PowerShell**:
- If you are using PowerShell, you can use `${PWD}` for the current directory:
```bash
docker run -p 4000:4000 --rm -v ${PWD}:/usr/src/app jekyll-site
```

2. **Enable Docker File Sharing**:
- If your volume doesn't map correctly, ensure Docker has access to the drive where your project resides. To do this:
- Open Docker Desktop.
- Go to *Settings* → *Resources* → *File Sharing*.
- Add your drive (e.g., `C:`).

3. **Run in Command Prompt or PowerShell**:
- In *Command Prompt*:

```bash
docker run -p 4000:4000 --rm -v C:\path\to\your\site:/usr/src/app jekyll-site
```
- In *PowerShell*:

```bash
docker run -p 4000:4000 --rm -v ${PWD}:/usr/src/app jekyll-site
```
You should now be able to access the website from `localhost:4000`.

# Maintenance

Expand Down
1 change: 1 addition & 0 deletions _config_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
url: ""
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
jekyll-site:
image: jekyll-site
build: .
volumes: [.:/usr/src/app]
ports: [4000:4000]
user: 1000:1000
environment: [JEKYLL_ENV=docker]