How can I make this docker image smaller?
up vote
-2
down vote
favorite
I have the following dockerfile:
FROM php:7.2-apache
LABEL name "medico-app"
COPY composer.json composer.lock ./
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y --no-install-recommends git zip && composer install
COPY . /var/www/html
EXPOSE 80
When this image is built, it has a size of ~500 Mbs. I'm trying to compress this image to < 100 Mb so that I can use it on Zeit Now. According to what I'm reading in the docker documentation, multi-stage builds sometimes help in making images smaller. My current idea is to split the dockerfile into two stages, one where I would install the dependencies with compose
and the other where I'd just have php
and apache
. I can't seem to get it right though. Any suggestions?
This is what I have so far:
# first stage
FROM composer:latest
COPY composer.json composer.lock ./
RUN composer install
For the second stage, I tried this
FROM httpd:2.4-alpine
LABEL name "medico-app"
COPY --from=0 /app/vendor ./vendor
COPY . /usr/local/apache2/htdocs/
EXPOSE 80
However when I run the container now, the php files aren't served, I just see them as text. Im probably missing something here with PHP/Apache.
EDIT:
I also tried this for the second stage but I can't get it to work:
FROM php:7.2-alpine
LABEL name "medico-app"
RUN apk --no-cache update && apk --no-cache add apache2 openrc
COPY --from=0 /app/vendor ./vendor
COPY . /var/www/
EXPOSE 80
Now when I open my localhost I don't see the PHP files that I should see. I just see the default it works
page.
php apache docker dockerfile
add a comment |
up vote
-2
down vote
favorite
I have the following dockerfile:
FROM php:7.2-apache
LABEL name "medico-app"
COPY composer.json composer.lock ./
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y --no-install-recommends git zip && composer install
COPY . /var/www/html
EXPOSE 80
When this image is built, it has a size of ~500 Mbs. I'm trying to compress this image to < 100 Mb so that I can use it on Zeit Now. According to what I'm reading in the docker documentation, multi-stage builds sometimes help in making images smaller. My current idea is to split the dockerfile into two stages, one where I would install the dependencies with compose
and the other where I'd just have php
and apache
. I can't seem to get it right though. Any suggestions?
This is what I have so far:
# first stage
FROM composer:latest
COPY composer.json composer.lock ./
RUN composer install
For the second stage, I tried this
FROM httpd:2.4-alpine
LABEL name "medico-app"
COPY --from=0 /app/vendor ./vendor
COPY . /usr/local/apache2/htdocs/
EXPOSE 80
However when I run the container now, the php files aren't served, I just see them as text. Im probably missing something here with PHP/Apache.
EDIT:
I also tried this for the second stage but I can't get it to work:
FROM php:7.2-alpine
LABEL name "medico-app"
RUN apk --no-cache update && apk --no-cache add apache2 openrc
COPY --from=0 /app/vendor ./vendor
COPY . /var/www/
EXPOSE 80
Now when I open my localhost I don't see the PHP files that I should see. I just see the default it works
page.
php apache docker dockerfile
You could purge apt lists after installing your dependencies to save some space:rm -rf /var/lib/apt/lists/*
. But your problem will be more likely hugevendor
folder.
– Martin Adámek
Nov 10 at 12:56
@martinadamek The vendor folder is actually less than 5 MBs. The problem is the base image itself is > 300 MB.
– ninesalt
Nov 10 at 13:06
Then maybe try installing alpine version of php and install apache manually.
– Martin Adámek
Nov 10 at 13:07
@martinadamek That's what I'm trying to do (my last edit).
– ninesalt
Nov 10 at 14:13
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I have the following dockerfile:
FROM php:7.2-apache
LABEL name "medico-app"
COPY composer.json composer.lock ./
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y --no-install-recommends git zip && composer install
COPY . /var/www/html
EXPOSE 80
When this image is built, it has a size of ~500 Mbs. I'm trying to compress this image to < 100 Mb so that I can use it on Zeit Now. According to what I'm reading in the docker documentation, multi-stage builds sometimes help in making images smaller. My current idea is to split the dockerfile into two stages, one where I would install the dependencies with compose
and the other where I'd just have php
and apache
. I can't seem to get it right though. Any suggestions?
This is what I have so far:
# first stage
FROM composer:latest
COPY composer.json composer.lock ./
RUN composer install
For the second stage, I tried this
FROM httpd:2.4-alpine
LABEL name "medico-app"
COPY --from=0 /app/vendor ./vendor
COPY . /usr/local/apache2/htdocs/
EXPOSE 80
However when I run the container now, the php files aren't served, I just see them as text. Im probably missing something here with PHP/Apache.
EDIT:
I also tried this for the second stage but I can't get it to work:
FROM php:7.2-alpine
LABEL name "medico-app"
RUN apk --no-cache update && apk --no-cache add apache2 openrc
COPY --from=0 /app/vendor ./vendor
COPY . /var/www/
EXPOSE 80
Now when I open my localhost I don't see the PHP files that I should see. I just see the default it works
page.
php apache docker dockerfile
I have the following dockerfile:
FROM php:7.2-apache
LABEL name "medico-app"
COPY composer.json composer.lock ./
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y --no-install-recommends git zip && composer install
COPY . /var/www/html
EXPOSE 80
When this image is built, it has a size of ~500 Mbs. I'm trying to compress this image to < 100 Mb so that I can use it on Zeit Now. According to what I'm reading in the docker documentation, multi-stage builds sometimes help in making images smaller. My current idea is to split the dockerfile into two stages, one where I would install the dependencies with compose
and the other where I'd just have php
and apache
. I can't seem to get it right though. Any suggestions?
This is what I have so far:
# first stage
FROM composer:latest
COPY composer.json composer.lock ./
RUN composer install
For the second stage, I tried this
FROM httpd:2.4-alpine
LABEL name "medico-app"
COPY --from=0 /app/vendor ./vendor
COPY . /usr/local/apache2/htdocs/
EXPOSE 80
However when I run the container now, the php files aren't served, I just see them as text. Im probably missing something here with PHP/Apache.
EDIT:
I also tried this for the second stage but I can't get it to work:
FROM php:7.2-alpine
LABEL name "medico-app"
RUN apk --no-cache update && apk --no-cache add apache2 openrc
COPY --from=0 /app/vendor ./vendor
COPY . /var/www/
EXPOSE 80
Now when I open my localhost I don't see the PHP files that I should see. I just see the default it works
page.
php apache docker dockerfile
php apache docker dockerfile
edited Nov 10 at 14:18
asked Nov 10 at 12:49
ninesalt
1,24011128
1,24011128
You could purge apt lists after installing your dependencies to save some space:rm -rf /var/lib/apt/lists/*
. But your problem will be more likely hugevendor
folder.
– Martin Adámek
Nov 10 at 12:56
@martinadamek The vendor folder is actually less than 5 MBs. The problem is the base image itself is > 300 MB.
– ninesalt
Nov 10 at 13:06
Then maybe try installing alpine version of php and install apache manually.
– Martin Adámek
Nov 10 at 13:07
@martinadamek That's what I'm trying to do (my last edit).
– ninesalt
Nov 10 at 14:13
add a comment |
You could purge apt lists after installing your dependencies to save some space:rm -rf /var/lib/apt/lists/*
. But your problem will be more likely hugevendor
folder.
– Martin Adámek
Nov 10 at 12:56
@martinadamek The vendor folder is actually less than 5 MBs. The problem is the base image itself is > 300 MB.
– ninesalt
Nov 10 at 13:06
Then maybe try installing alpine version of php and install apache manually.
– Martin Adámek
Nov 10 at 13:07
@martinadamek That's what I'm trying to do (my last edit).
– ninesalt
Nov 10 at 14:13
You could purge apt lists after installing your dependencies to save some space:
rm -rf /var/lib/apt/lists/*
. But your problem will be more likely huge vendor
folder.– Martin Adámek
Nov 10 at 12:56
You could purge apt lists after installing your dependencies to save some space:
rm -rf /var/lib/apt/lists/*
. But your problem will be more likely huge vendor
folder.– Martin Adámek
Nov 10 at 12:56
@martinadamek The vendor folder is actually less than 5 MBs. The problem is the base image itself is > 300 MB.
– ninesalt
Nov 10 at 13:06
@martinadamek The vendor folder is actually less than 5 MBs. The problem is the base image itself is > 300 MB.
– ninesalt
Nov 10 at 13:06
Then maybe try installing alpine version of php and install apache manually.
– Martin Adámek
Nov 10 at 13:07
Then maybe try installing alpine version of php and install apache manually.
– Martin Adámek
Nov 10 at 13:07
@martinadamek That's what I'm trying to do (my last edit).
– ninesalt
Nov 10 at 14:13
@martinadamek That's what I'm trying to do (my last edit).
– ninesalt
Nov 10 at 14:13
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
General tips for making docker images smaller:
- Use a minimal base image such as the alpine versions. In this case you can use something like
php:7.2-alpine
and install apache using apk. - When using apt-get follow the best practices. In particular add
&& rm -rf /var/lib/apt/lists/*
- Try minifiying the code being added to the image using something like gulp minify.
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
General tips for making docker images smaller:
- Use a minimal base image such as the alpine versions. In this case you can use something like
php:7.2-alpine
and install apache using apk. - When using apt-get follow the best practices. In particular add
&& rm -rf /var/lib/apt/lists/*
- Try minifiying the code being added to the image using something like gulp minify.
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
add a comment |
up vote
0
down vote
General tips for making docker images smaller:
- Use a minimal base image such as the alpine versions. In this case you can use something like
php:7.2-alpine
and install apache using apk. - When using apt-get follow the best practices. In particular add
&& rm -rf /var/lib/apt/lists/*
- Try minifiying the code being added to the image using something like gulp minify.
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
add a comment |
up vote
0
down vote
up vote
0
down vote
General tips for making docker images smaller:
- Use a minimal base image such as the alpine versions. In this case you can use something like
php:7.2-alpine
and install apache using apk. - When using apt-get follow the best practices. In particular add
&& rm -rf /var/lib/apt/lists/*
- Try minifiying the code being added to the image using something like gulp minify.
General tips for making docker images smaller:
- Use a minimal base image such as the alpine versions. In this case you can use something like
php:7.2-alpine
and install apache using apk. - When using apt-get follow the best practices. In particular add
&& rm -rf /var/lib/apt/lists/*
- Try minifiying the code being added to the image using something like gulp minify.
answered Nov 10 at 13:47
yamenk
10.9k31125
10.9k31125
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
add a comment |
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
I'm trying to do your first suggestions. I installed apache in the php:7.2 image however I can't figure out how to run it correctly and where to put my files.
– ninesalt
Nov 10 at 13:57
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239114%2fhow-can-i-make-this-docker-image-smaller%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You could purge apt lists after installing your dependencies to save some space:
rm -rf /var/lib/apt/lists/*
. But your problem will be more likely hugevendor
folder.– Martin Adámek
Nov 10 at 12:56
@martinadamek The vendor folder is actually less than 5 MBs. The problem is the base image itself is > 300 MB.
– ninesalt
Nov 10 at 13:06
Then maybe try installing alpine version of php and install apache manually.
– Martin Adámek
Nov 10 at 13:07
@martinadamek That's what I'm trying to do (my last edit).
– ninesalt
Nov 10 at 14:13