构建Python Flask应用程序的Docker镜像

时间:2017-01-19 19:46:32

标签: python docker flask

我正在尝试为Python Flask应用程序构建Docker镜像,但是存在构建问题 - 所有文件都存在于名为web的文件夹中 - 这是项目结构:

web/
    __init__.py
    app.py
    Dockerfile
    models.py
    requirements.txt
目前

app.py看起来像这样:

from flask import Flask


app = Flask(__name__)

@app.route("/")
def hello_world():
    return "Hello World!"


if __name__ == "__main__":
    app.run(debug=True,host='0.0.0.0')

我已经从https://www.smartfile.com/blog/dockerizing-a-python-flask-application/借用了Dockerfile

FROM ubuntu:14.04

# Update OS
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y upgrade

# Install Python
RUN apt-get install -y python-dev python-pip

# Add requirements.txt
ADD requirements.txt /webapp

# Install wsgi Python web server
RUN pip install uwsgi
# Install app requirements
RUN pip install -r requirements.txt

# Create app directory
ADD . /webapp

# Set the default directory for our environment
ENV HOME /webapp
WORKDIR /webapp

# Expose port 8000 for uwsgi
EXPOSE 8000

ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]

我正在尝试使用docker build --no-cache --rm -t flask-app构建Docker镜像,但它以错误消息结束:

Successfully installed uwsgi
Cleaning up...
 ---> 9bbc004212a3
Removing intermediate container 70ed8f07c408
Step 8/13 : RUN pip install -r requirements.txt
 ---> Running in f5e2eb59ffd1
Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
Storing debug log for failure in /root/.pip/pip.log
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

3 个答案:

答案 0 :(得分:4)

我认为Dockerfile上的一个非常小的变化可以解决这个问题:

structure(list(tp = c(1.5, 1, 0.5, 4.5), f.ecdf = c(0.887918176006819, 
0.812380140634988, 0.760387811634349, 0.0372895802258683)), na.action = structure(c(970L, 
975L, 976L, 978L, 981L, 982L, 983L, 986L, 988L, 989L, 990L, 991L, 
992L, 993L, 996L, 997L, 999L, 1000L, 1001L, 1005L, 1007L, 1008L, 
1331L, 1336L, 1442L, 1526L, 1779L, 1781L, 1782L, 1784L, 1785L, 
1786L, 1787L, 1788L, 1789L, 1790L, 1793L, 1797L, 1798L, 1801L, 
1802L, 1804L, 1805L, 1806L, 1807L, 1808L, 1809L, 1810L, 1813L, 
1814L, 1818L, 1819L, 1820L, 1821L, 1825L, 1826L, 1827L, 1828L, 
1829L, 1830L, 1831L, 1832L, 1833L, 1834L, 1835L, 1836L, 1837L, 
1838L, 1839L, 1840L, 1841L, 1845L, 1846L, 1847L, 1848L, 1849L, 
1850L, 1851L, 1854L, 1856L, 1860L, 1862L, 1865L, 1867L, 1871L, 
1872L, 1873L, 1875L, 1876L, 1878L, 1892L, 1895L, 1906L, 1909L, 
1910L, 1912L, 1927L, 1930L, 1932L, 1933L, 1936L, 1939L, 1941L, 
1945L, 1949L, 1950L, 1958L, 1961L, 1964L, 1965L, 1967L, 2008L, 
2010L, 2017L, 2019L, 2025L, 2026L, 2028L, 2029L, 2034L, 2048L, 
2049L, 2050L, 2052L, 2053L, 2054L, 2056L, 2057L, 2058L, 2059L, 
2060L, 2065L, 2070L, 2072L, 2084L, 2086L, 2088L, 2091L, 2093L, 
2094L, 2095L, 2096L, 2097L, 2100L, 2101L, 2103L, 2105L, 2107L, 
2108L, 2110L, 2113L, 2115L, 2117L, 2122L, 2124L, 2125L, 2126L, 
2128L, 2129L, 2130L, 2134L, 2135L, 2136L, 2137L, 2140L, 2141L, 
2142L, 2144L, 2147L, 2148L, 2149L, 2150L, 2152L, 2153L, 2155L, 
2157L, 2158L, 2159L, 2160L, 2161L, 2162L, 2163L, 2164L, 2581L, 
2604L, 2613L, 2615L, 2623L, 2624L, 2663L, 2664L, 2666L, 2676L, 
2701L, 2704L, 2707L, 2711L, 2716L, 2717L, 2718L, 2721L, 2722L, 
2724L, 2725L, 2726L, 2728L, 2733L, 2735L, 2737L, 2824L, 2834L, 
2836L, 2837L, 2841L, 2843L, 2846L, 2851L, 2853L, 2854L, 2855L, 
2856L, 2857L, 2859L, 2860L, 2861L, 2862L, 2863L, 2864L, 2865L, 
2867L, 2868L, 2872L, 2873L, 2876L, 2877L, 2878L, 2879L, 2880L, 
2881L, 2884L, 2885L, 2886L, 2887L, 2889L, 2890L, 2891L, 2892L, 
2893L, 2894L, 2895L, 2896L, 2897L, 2898L, 2899L, 2901L, 2902L, 
2903L, 2904L, 2905L, 2906L, 2907L, 2908L, 2933L, 2952L, 3066L, 
3075L, 3087L, 3089L, 3091L, 3114L, 3116L, 3120L, 3122L, 3124L, 
3125L, 3127L, 3128L, 3147L, 3151L, 3152L, 3166L, 3168L, 3174L, 
3175L, 3176L, 3177L, 3179L, 3180L, 3182L, 3183L, 3185L, 3186L, 
3187L, 3191L, 3192L, 3193L, 3194L, 3195L, 3196L, 3197L, 3199L, 
3200L, 3202L, 3204L, 3207L, 3209L, 3211L, 3219L, 3222L, 3228L, 
3230L, 3232L, 3234L, 3235L, 3237L, 3241L, 3243L, 3244L, 3245L, 
3246L, 3247L, 3248L, 3249L, 3250L, 3251L, 3252L, 3253L, 3257L, 
3258L, 3259L, 3261L, 3266L, 3267L, 3268L, 3269L, 3270L, 3273L, 
3275L, 3280L, 3282L, 3289L, 3294L, 3295L, 3301L, 3302L, 3304L, 
3306L, 3308L, 3346L, 3349L, 3350L, 3577L, 3580L, 3584L, 3588L, 
3810L, 3822L, 3823L, 3832L, 3866L, 3888L, 3911L, 3913L, 3915L, 
3923L, 3924L, 3927L, 3928L, 3929L, 3959L, 3963L, 3968L, 3976L, 
3980L, 3987L, 3989L, 3992L, 4076L, 4100L, 4115L, 4117L, 4119L, 
4122L, 4123L, 4124L, 4125L, 4128L, 4131L, 4133L, 4136L, 4138L, 
4175L, 4178L, 4182L, 4186L, 4197L, 4222L, 4228L, 4235L, 4326L, 
4341L, 4355L, 4358L, 4361L, 4367L, 4376L, 4381L, 4386L, 4402L, 
4633L, 4634L, 4643L, 4711L, 4715L, 4717L, 4866L, 4922L, 4934L, 
4951L, 4964L, 4970L, 4971L, 4975L, 4982L, 4985L, 4989L, 4990L, 
4994L, 4996L, 4997L, 4999L, 5001L, 5012L, 5014L, 5018L, 5019L, 
5022L, 5028L, 5030L, 5031L, 5032L, 5033L, 5041L, 5046L, 5057L, 
5079L, 5085L, 5093L, 5106L, 5108L, 5112L, 5128L, 5130L, 5133L, 
5135L, 5137L, 5140L, 5144L, 5146L, 5149L, 5152L, 5157L, 5159L, 
5168L, 5172L, 5179L, 5190L, 5191L, 5192L, 5193L, 5197L, 5199L, 
5201L, 5202L, 5204L, 5213L, 5215L, 5216L, 5218L, 5219L, 5220L, 
5224L, 5229L, 5232L, 5238L, 5242L, 5243L, 5250L, 5253L, 5254L, 
5259L, 5265L, 5266L, 5269L, 5272L, 5273L, 5275L, 5276L, 5277L, 
5278L, 5279L, 5284L, 5286L, 5288L, 5387L, 5389L, 5391L, 5401L, 
5412L, 5443L, 5454L, 5489L, 5499L, 5506L, 5510L, 5511L, 5513L, 
5514L, 5515L, 5520L, 5522L, 5523L, 5526L, 5530L, 5531L, 5532L, 
5534L, 5535L, 5536L, 5537L, 5538L, 5544L, 5546L, 5549L, 5554L, 
5555L, 5556L, 5559L, 5561L, 5567L, 5570L, 5574L, 5575L, 5576L, 
5577L, 5578L, 5581L, 5583L, 5585L, 5591L, 5592L, 5594L, 5595L, 
5597L, 5598L, 5599L, 5600L, 5603L, 5604L, 5607L, 5609L, 5610L, 
5611L, 5612L, 5614L, 5615L, 5616L, 5618L, 5619L, 5620L, 5621L, 
5622L, 5623L, 5624L, 5625L, 5627L, 5628L, 5629L, 5636L, 5637L, 
5638L, 5639L, 5640L, 5641L, 5642L, 5643L, 5644L, 5645L, 5646L, 
5647L, 5648L, 5650L, 5654L, 5655L, 5657L, 5660L, 5661L, 5662L, 
5664L, 5665L, 5668L, 5670L, 5671L, 5673L, 5674L, 5676L, 5678L, 
5679L, 5681L, 5683L, 5684L, 5685L, 5686L, 5687L, 5688L, 5693L, 
5696L, 5700L, 5701L, 5703L, 5706L, 5716L, 5719L, 5723L, 5729L, 
5732L, 5735L, 5737L, 5741L, 5742L, 5743L, 5751L, 5752L, 5753L, 
5757L, 5759L, 5760L, 5765L, 5802L, 5810L, 5811L, 5822L, 5906L, 
5922L, 6079L, 6090L, 6094L, 6099L, 6103L, 6105L, 6110L, 6117L, 
6121L, 6123L, 6126L, 6127L, 6132L, 6138L, 6141L, 6142L, 6145L, 
6147L, 6154L, 6193L, 6195L, 6209L, 6214L, 6309L, 6414L, 6506L, 
6514L, 6532L, 6539L, 6542L, 6543L, 6572L, 6573L, 6582L, 6583L, 
6587L, 6591L, 6594L, 6597L, 6600L, 6603L, 6610L, 6611L, 6614L, 
6620L, 6637L, 6641L, 6643L, 6644L, 6648L, 6649L, 6650L, 6661L, 
6662L, 6663L, 6667L, 6669L, 6671L, 6682L, 6683L, 6684L, 6685L, 
6691L, 6694L, 6695L, 6699L, 6701L, 6726L, 6728L, 6729L, 6732L, 
6733L, 6734L, 6735L, 6738L, 6746L, 6748L, 6751L, 6752L, 6754L, 
6759L, 6760L, 6764L, 6766L, 6769L, 6770L, 6771L, 6773L, 6776L, 
6777L, 6783L, 6784L, 6786L, 6787L, 6789L, 6793L, 6794L, 6805L, 
6806L, 6807L, 6931L, 6954L, 6992L, 6995L, 7005L, 7006L, 7012L, 
7013L, 7021L, 7025L, 7028L, 7029L, 7032L, 7036L, 7047L, 7061L, 
7066L, 7068L, 7074L, 7077L, 7081L, 7083L, 7086L, 7088L, 7089L, 
7093L, 7101L, 7108L, 7112L, 7114L, 7124L, 7126L, 7129L, 7133L, 
7135L, 7136L, 7138L, 7165L, 7168L, 7169L, 7180L, 7181L, 7224L, 
7225L, 7229L, 7232L, 7241L, 7242L, 7249L, 7414L, 7418L, 7465L, 
7467L, 7469L, 7472L, 7474L, 7477L, 7479L, 7524L, 7536L, 7570L, 
7579L, 7588L, 7600L, 7604L, 7938L, 7997L, 8001L, 8006L, 8022L, 
8037L, 8041L, 8045L, 8053L, 8058L, 8061L, 8062L, 8068L, 8077L, 
8078L, 8082L, 8084L, 8085L, 8089L, 8092L, 8093L, 8105L, 8117L, 
8126L, 8132L, 8133L, 8139L, 8140L, 8144L, 8155L, 8162L, 8163L, 
8167L, 8173L, 8176L, 8178L, 8181L, 8184L, 8186L, 8188L, 8196L, 
8199L, 8201L, 8203L, 8206L, 8207L, 8222L, 8227L, 8231L, 8234L, 
8236L, 8249L, 8253L, 8254L, 8274L, 8280L, 8282L, 8286L, 8287L, 
8295L, 8299L, 8305L, 8307L, 8309L, 8321L, 8323L, 8325L, 8332L, 
8393L, 8426L, 8443L, 8461L, 8463L, 8482L, 8497L, 8500L, 8515L, 
8519L, 8523L, 8553L, 8564L, 8575L, 8589L, 8638L, 8653L, 8672L, 
8678L, 8692L, 8694L, 8699L, 8755L, 8777L, 8793L, 8795L, 8817L, 
8823L, 8825L, 8841L, 8846L, 8852L, 8867L, 8906L, 8918L, 8928L, 
8939L, 8946L, 8950L, 8961L, 8972L, 8973L, 8975L, 8976L, 9019L, 
9024L, 9051L, 9056L, 9064L, 9076L, 9080L, 9094L, 9097L, 9098L, 
9109L, 9111L, 9124L, 9128L, 9142L, 9158L, 9168L, 9169L, 9175L, 
9179L, 9182L, 9185L, 9186L, 9187L, 9189L, 9191L, 9195L, 9196L, 
9197L, 9200L, 9201L, 9204L, 9210L, 9226L, 9240L, 9251L, 9253L, 
9254L, 9255L, 9264L, 9271L, 9279L, 9281L, 9282L, 9288L, 9293L, 
9304L, 9313L, 9315L, 9317L, 9320L, 9325L, 9327L, 9332L, 9336L, 
9343L, 9344L, 9346L, 9347L, 9348L, 9352L, 9357L, 9363L, 9365L, 
9368L, 9371L, 9375L, 9378L, 9380L), .Names = c("970", "975", 
"976", "978", "981", "982", "983", "986", "988", "989", "990", 
"991", "992", "993", "996", "997", "999", "1000", "1001", "1005", 
"1007", "1008", "1331", "1336", "1442", "1526", "1779", "1781", 
"1782", "1784", "1785", "1786", "1787", "1788", "1789", "1790", 
"1793", "1797", "1798", "1801", "1802", "1804", "1805", "1806", 
"1807", "1808", "1809", "1810", "1813", "1814", "1818", "1819", 
"1820", "1821", "1825", "1826", "1827", "1828", "1829", "1830", 
"1831", "1832", "1833", "1834", "1835", "1836", "1837", "1838", 
"1839", "1840", "1841", "1845", "1846", "1847", "1848", "1849", 
"1850", "1851", "1854", "1856", "1860", "1862", "1865", "1867", 
"1871", "1872", "1873", "1875", "1876", "1878", "1892", "1895", 
"1906", "1909", "1910", "1912", "1927", "1930", "1932", "1933", 
"1936", "1939", "1941", "1945", "1949", "1950", "1958", "1961", 
"1964", "1965", "1967", "2008", "2010", "2017", "2019", "2025", 
"2026", "2028", "2029", "2034", "2048", "2049", "2050", "2052", 
"2053", "2054", "2056", "2057", "2058", "2059", "2060", "2065", 
"2070", "2072", "2084", "2086", "2088", "2091", "2093", "2094", 
"2095", "2096", "2097", "2100", "2101", "2103", "2105", "2107", 
"2108", "2110", "2113", "2115", "2117", "2122", "2124", "2125", 
"2126", "2128", "2129", "2130", "2134", "2135", "2136", "2137", 
"2140", "2141", "2142", "2144", "2147", "2148", "2149", "2150", 
"2152", "2153", "2155", "2157", "2158", "2159", "2160", "2161", 
"2162", "2163", "2164", "2581", "2604", "2613", "2615", "2623", 
"2624", "2663", "2664", "2666", "2676", "2701", "2704", "2707", 
"2711", "2716", "2717", "2718", "2721", "2722", "2724", "2725", 
"2726", "2728", "2733", "2735", "2737", "2824", "2834", "2836", 
"2837", "2841", "2843", "2846", "2851", "2853", "2854", "2855", 
"2856", "2857", "2859", "2860", "2861", "2862", "2863", "2864", 
"2865", "2867", "2868", "2872", "2873", "2876", "2877", "2878", 
"2879", "2880", "2881", "2884", "2885", "2886", "2887", "2889", 
"2890", "2891", "2892", "2893", "2894", "2895", "2896", "2897", 
"2898", "2899", "2901", "2902", "2903", "2904", "2905", "2906", 
"2907", "2908", "2933", "2952", "3066", "3075", "3087", "3089", 
"3091", "3114", "3116", "3120", "3122", "3124", "3125", "3127", 
"3128", "3147", "3151", "3152", "3166", "3168", "3174", "3175", 
"3176", "3177", "3179", "3180", "3182", "3183", "3185", "3186", 
"3187", "3191", "3192", "3193", "3194", "3195", "3196", "3197", 
"3199", "3200", "3202", "3204", "3207", "3209", "3211", "3219", 
"3222", "3228", "3230", "3232", "3234", "3235", "3237", "3241", 
"3243", "3244", "3245", "3246", "3247", "3248", "3249", "3250", 
"3251", "3252", "3253", "3257", "3258", "3259", "3261", "3266", 
"3267", "3268", "3269", "3270", "3273", "3275", "3280", "3282", 
"3289", "3294", "3295", "3301", "3302", "3304", "3306", "3308", 
"3346", "3349", "3350", "3577", "3580", "3584", "3588", "3810", 
"3822", "3823", "3832", "3866", "3888", "3911", "3913", "3915", 
"3923", "3924", "3927", "3928", "3929", "3959", "3963", "3968", 
"3976", "3980", "3987", "3989", "3992", "4076", "4100", "4115", 
"4117", "4119", "4122", "4123", "4124", "4125", "4128", "4131", 
"4133", "4136", "4138", "4175", "4178", "4182", "4186", "4197", 
"4222", "4228", "4235", "4326", "4341", "4355", "4358", "4361", 
"4367", "4376", "4381", "4386", "4402", "4633", "4634", "4643", 
"4711", "4715", "4717", "4866", "4922", "4934", "4951", "4964", 
"4970", "4971", "4975", "4982", "4985", "4989", "4990", "4994", 
"4996", "4997", "4999", "5001", "5012", "5014", "5018", "5019", 
"5022", "5028", "5030", "5031", "5032", "5033", "5041", "5046", 
"5057", "5079", "5085", "5093", "5106", "5108", "5112", "5128", 
"5130", "5133", "5135", "5137", "5140", "5144", "5146", "5149", 
"5152", "5157", "5159", "5168", "5172", "5179", "5190", "5191", 
"5192", "5193", "5197", "5199", "5201", "5202", "5204", "5213", 
"5215", "5216", "5218", "5219", "5220", "5224", "5229", "5232", 
"5238", "5242", "5243", "5250", "5253", "5254", "5259", "5265", 
"5266", "5269", "5272", "5273", "5275", "5276", "5277", "5278", 
"5279", "5284", "5286", "5288", "5387", "5389", "5391", "5401", 
"5412", "5443", "5454", "5489", "5499", "5506", "5510", "5511", 
"5513", "5514", "5515", "5520", "5522", "5523", "5526", "5530", 
"5531", "5532", "5534", "5535", "5536", "5537", "5538", "5544", 
"5546", "5549", "5554", "5555", "5556", "5559", "5561", "5567", 
"5570", "5574", "5575", "5576", "5577", "5578", "5581", "5583", 
"5585", "5591", "5592", "5594", "5595", "5597", "5598", "5599", 
"5600", "5603", "5604", "5607", "5609", "5610", "5611", "5612", 
"5614", "5615", "5616", "5618", "5619", "5620", "5621", "5622", 
"5623", "5624", "5625", "5627", "5628", "5629", "5636", "5637", 
"5638", "5639", "5640", "5641", "5642", "5643", "5644", "5645", 
"5646", "5647", "5648", "5650", "5654", "5655", "5657", "5660", 
"5661", "5662", "5664", "5665", "5668", "5670", "5671", "5673", 
"5674", "5676", "5678", "5679", "5681", "5683", "5684", "5685", 
"5686", "5687", "5688", "5693", "5696", "5700", "5701", "5703", 
"5706", "5716", "5719", "5723", "5729", "5732", "5735", "5737", 
"5741", "5742", "5743", "5751", "5752", "5753", "5757", "5759", 
"5760", "5765", "5802", "5810", "5811", "5822", "5906", "5922", 
"6079", "6090", "6094", "6099", "6103", "6105", "6110", "6117", 
"6121", "6123", "6126", "6127", "6132", "6138", "6141", "6142", 
"6145", "6147", "6154", "6193", "6195", "6209", "6214", "6309", 
"6414", "6506", "6514", "6532", "6539", "6542", "6543", "6572", 
"6573", "6582", "6583", "6587", "6591", "6594", "6597", "6600", 
"6603", "6610", "6611", "6614", "6620", "6637", "6641", "6643", 
"6644", "6648", "6649", "6650", "6661", "6662", "6663", "6667", 
"6669", "6671", "6682", "6683", "6684", "6685", "6691", "6694", 
"6695", "6699", "6701", "6726", "6728", "6729", "6732", "6733", 
"6734", "6735", "6738", "6746", "6748", "6751", "6752", "6754", 
"6759", "6760", "6764", "6766", "6769", "6770", "6771", "6773", 
"6776", "6777", "6783", "6784", "6786", "6787", "6789", "6793", 
"6794", "6805", "6806", "6807", "6931", "6954", "6992", "6995", 
"7005", "7006", "7012", "7013", "7021", "7025", "7028", "7029", 
"7032", "7036", "7047", "7061", "7066", "7068", "7074", "7077", 
"7081", "7083", "7086", "7088", "7089", "7093", "7101", "7108", 
"7112", "7114", "7124", "7126", "7129", "7133", "7135", "7136", 
"7138", "7165", "7168", "7169", "7180", "7181", "7224", "7225", 
"7229", "7232", "7241", "7242", "7249", "7414", "7418", "7465", 
"7467", "7469", "7472", "7474", "7477", "7479", "7524", "7536", 
"7570", "7579", "7588", "7600", "7604", "7938", "7997", "8001", 
"8006", "8022", "8037", "8041", "8045", "8053", "8058", "8061", 
"8062", "8068", "8077", "8078", "8082", "8084", "8085", "8089", 
"8092", "8093", "8105", "8117", "8126", "8132", "8133", "8139", 
"8140", "8144", "8155", "8162", "8163", "8167", "8173", "8176", 
"8178", "8181", "8184", "8186", "8188", "8196", "8199", "8201", 
"8203", "8206", "8207", "8222", "8227", "8231", "8234", "8236", 
"8249", "8253", "8254", "8274", "8280", "8282", "8286", "8287", 
"8295", "8299", "8305", "8307", "8309", "8321", "8323", "8325", 
"8332", "8393", "8426", "8443", "8461", "8463", "8482", "8497", 
"8500", "8515", "8519", "8523", "8553", "8564", "8575", "8589", 
"8638", "8653", "8672", "8678", "8692", "8694", "8699", "8755", 
"8777", "8793", "8795", "8817", "8823", "8825", "8841", "8846", 
"8852", "8867", "8906", "8918", "8928", "8939", "8946", "8950", 
"8961", "8972", "8973", "8975", "8976", "9019", "9024", "9051", 
"9056", "9064", "9076", "9080", "9094", "9097", "9098", "9109", 
"9111", "9124", "9128", "9142", "9158", "9168", "9169", "9175", 
"9179", "9182", "9185", "9186", "9187", "9189", "9191", "9195", 
"9196", "9197", "9200", "9201", "9204", "9210", "9226", "9240", 
"9251", "9253", "9254", "9255", "9264", "9271", "9279", "9281", 
"9282", "9288", "9293", "9304", "9313", "9315", "9317", "9320", 
"9325", "9327", "9332", "9336", "9343", "9344", "9346", "9347", 
"9348", "9352", "9357", "9363", "9365", "9368", "9371", "9375", 
"9378", "9380"), class = "omit"), .Names = c("tp", "f.ecdf"), row.names = c(NA, 
4L), class = "data.frame")

我刚刚添加了FROM ubuntu:14.04 # Update OS RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list RUN apt-get update RUN apt-get -y upgrade # Install Python RUN apt-get install -y python-dev python-pip # Add requirements.txt # Create app directory ADD . /webapp # Install wsgi Python web server RUN pip install uwsgi # Install app requirements # Full path to requirements RUN pip install -r /webapp/requirements.txt # Set the default directory for our environment ENV HOME /webapp WORKDIR /webapp # Expose port 8000 for uwsgi EXPOSE 8000 ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"] 的完整路径,这可以通过几种不同的方式完成,例如复制整个目录文件夹然后构建它。

答案 1 :(得分:0)

在使用

添加需求之前,我替换了Dockerfile的初始行
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential

它成功构建了图像。

$ docker images
REPOSITORY          TAG                 IMAGE ID                CREATED             SIZE
flask-app           latest              32b81efb5719        2 minutes ago       644.9 MB
ubuntu              latest              104bec311bcd        5 weeks ago         129 MB
$
$ docker run -d flask-app
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
73ae8baa93c2        flask-app       "uwsgi --http 0.0.0.0"   6 seconds ago       Up 5 seconds        8000/tcp            lucid_heyrovsky
$
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 73ae8baa93c2
172.17.0.2

因此,当我尝试指向网址http://172.17.0.2:8000/时,我什么都没得到。

答案 2 :(得分:0)

添加

WORKDIR /webapp

之前

RUN pip install -r requirements.txt